Home > Blockchain >  I can't find postgresql tables in Docker container
I can't find postgresql tables in Docker container

Time:11-15

There is a Java project. The project is not mine. I'm trying to deal with him. There is an authorization service:

spring:
  profiles:
    active: @spring.profiles.active@
  jpa:
    hibernate:
      ddl-auto: none
  datasource:
    initialization-mode: always
    platform: authentication
    driver-class-name: org.postgresql.Driver
    username: postgres
    password: postgres
    url: jdbc:postgresql://localhost:5432/mark_authentication
    jdbc-url: jdbc:postgresql://localhost:5432/mark_authentication
  liquibase:
    change-log: classpath:db/changelog.xml

Here is the file for liquibase

    <changeSet  id="create_roles"  author="afanasev">
        <createTable  tableName="roles" schemaName="users">
            <column  name="id"  type="BIGINT"  autoIncrement="true">
                <constraints  primaryKey="true"  nullable="false"/>
            </column>
            <column  name="role_name"  type="varchar(25)"/>
        </createTable>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="0"/>
            <column  name="role_name"  value="ROLE_SUBSCRIBER"/>
        </insert>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="1"/>
            <column  name="role_name"  value="ROLE_MARKETPLACE"/>
        </insert>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="2"/>
            <column  name="role_name"  value="ROLE_ADMIN"/>
        </insert>
    </changeSet>
    <changeSet  id="create_users"  author="afanasev">
        <createTable  tableName="users" schemaName="users">
            <column  name="id"  type="VARCHAR(255)"  autoIncrement="false">
                <constraints  primaryKey="true"  nullable="false"/>
            </column>
            <column  name="password"  type="VARCHAR(50)">
                <constraints  nullable="false"/>
            </column>
            <column  name="email"  type="VARCHAR(50)">
                <constraints  nullable="false"/>
            </column>
            <column  name="full_name"  type="VARCHAR(255)">
                <constraints  nullable="false"/>
            </column>
            <column  name="is_active"  type="boolean" defaultValueBoolean="false">
                <constraints  nullable="false"/>
            </column>
            <column  name="date_added"  type="timestamp" defaultValueComputed="current_timestamp">
                <constraints  nullable="false"/>
            </column>
            <column  name="id_role"  type="INT">
                <constraints nullable="false" foreignKeyName="fk_role" referencedTableSchemaName="users" referencedTableName="roles" referencedColumnNames="id"/>
            </column>
            <column  name="code"  type="int"/>
        </createTable>
    </changeSet>
    <changeSet  id="update_users"  author="afanasev">
        <addColumn tableName="users" schemaName="users">
            <column name="address" type="VARCHAR(255)"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="tax_identification_number" type="BIGINT"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="organization" type="VARCHAR(255)"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="msisdn" type="BIGINT"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="code_reason" type="BIGINT"/>
        </addColumn>
    </changeSet>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Here is the docker-compose file

  postgres-authentication:
    container_name: postgres-authentication
    image: postgres:13.2-alpine
    restart: unless-stopped
    ports:
      - "5433:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=authentication
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./postgres_authentication_data:/var/lib/postgresql/data

The application is working and spinning on the server. I go into the docker container

docker exec -it postgres-authentication bash

Connecting to the database

\c authentication

and I don't see any tables there, except logs

\dt
Schema |         Name          | Type  |  Owner
-------- ----------------------- ------- ----------
 public | databasechangelog     | table | postgres
 public | databasechangeloglock | table | postgres

I look at the logs, changelog has worked there and tables have been created.

create_roles | afanasev | db/changelog/01-create-user.xml | 2021-07-01 20:03:45.70403  |             1 | EXECUTED | 8:f576f05834bc714dda20a2e6580fd2de | createTable tableName=roles; insert tableName=roles; insert tableName=roles; insert tableName=roles                                   |          |     | 3.10.3    |          |        | 5169825313
create_users | afanasev | db/changelog/01-create-user.xml | 2021-07-01 20:03:46.039663 |             2 | EXECUTED | 8:f0f6055fe52f20bd3123bb53b38071de | createTable tableName=users                                                                                                           |          |     | 3.10.3    |          |        | 5169825313

And the fact is that I am registering and it works, i.e. it adds a user and I can log in under it. But then where do these tables lie? Maybe I'm not looking there?

CodePudding user response:

When using \dt, default show only public schema

If you want to show all tables of schema you should use \dtS or use \dt [PATTERN]

If use \dtS, You see all schema of the database include Postgres schema like pg_catalog

But if use \dt [PATTERN], You can see just schema pattern matched with your expected. like below:

-- just show users schema
\dt users
  • Related