-
Notifications
You must be signed in to change notification settings - Fork 0
SQL: Add 'migration' file #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great. thank you! could we add directions in the readme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at this again, i'm seeing the following on running from a freshly built image on a new container:
GDKJFQ1GXT:willa matienzo$ docker compose exec app bin/dbinit
createdb: error: database creation failed: ERROR: database "willa" already exists
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
SET
psql:sql/willa.sql:18: ERROR: role "willa" does not exist
psql:sql/willa.sql:21: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:22: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:36: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:39: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:40: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:60: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:71: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:89: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:101: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:110: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:122: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:126: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:129: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:132: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:135: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:138: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:141: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:144: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:146: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:148: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:150: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:152: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:154: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:156: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:158: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:160: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:162: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:164: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:166: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:168: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:170: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:172: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:174: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:176: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:178: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:181: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:185: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:188: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:191: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:194: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:197: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:sql/willa.sql:200: ERROR: current transaction is aborted, commands ignored until end of transaction block
this is happening also if the containers are down and i run docker compose run app bin/dbinit instead.
1551bf8 to
f0da99e
Compare
|
Changes in v2:
|
f0da99e to
691bd24
Compare
|
Changes in v3:
|
691bd24 to
d5a616e
Compare
|
Rebased atop |
| @@ -0,0 +1,205 @@ | |||
| -- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to get this running, and it also includes a number of statements (e.g. the grants) which go beyond the scope of just establishing the schema.
What about cat-ing together the migration files that ship with prisma (in prisma/migrations/*/migration.sql)? That would be identical to what it seems prisma is doing under the hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GRANT was needed in my testing because the database created by default in Docker doesn't allow the created role to create tables in the public schema. (It wasn't part of the original pg_dump.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed some of the superfluous sets that are already defaults. What failure were you seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That GRANT line is not necessary in my testing. Steps to reproduce:
- Hard reset to the current code version.
- Remove or comment out the GRANT line.
- Down the stack (remove orphans and volumes)
- Delete .data/postgres1:
rm -rf .data/postgres - Start the stack:
docker compose up --build -d app db - Run dbinit:
docker compose exec app bin/dbinit2
1 Should we use a named volume here instead? I found this confusing as it means docker compose down -v doesn't actually delete the data, which has to be rm'd manually. (Not necessary for this PR IMO, just raising the Q.)
2 Or, equivalently, use docker compose run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following those exact steps, I get:
psql:sql/willa.sql:10: ERROR: no schema has been selected to create in
And this is because the public schema does not allow CREATE to willa:
willa=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+-------------------+----------------------------------------+------------------------
public | pg_database_owner | pg_database_owner=UC/pg_database_owner+| standard public schema
| | =U/pg_database_owner |
(1 row)
willa=# GRANT CREATE ON SCHEMA public TO willa;
GRANT
willa=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+-------------------+----------------------------------------+------------------------
public | pg_database_owner | pg_database_owner=UC/pg_database_owner+| standard public schema
| | =U/pg_database_owner +|
| | willa=C/pg_database_owner |
(1 row)
Now the real question is why willa isn't inheriting it, because as far as I can tell, willa is the owner:
willa=# \l willa
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-------+-------+----------+-----------------+------------+------------+--------+-----------+-------------------
willa | willa | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created AP-472 for the named volumes issue.
d5a616e to
c759c67
Compare
|
Changes in v5:
|
danschmidt5189
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Softly requesting two changes but they're not critical:
- PGPASSWORD doesn't need to be set multiple times in dbinit.
- The GRANT in the schema dump does not appear to be necessary based on my testing with a fresh instance.
Besides that it looks good, let's get this in!
Allows for the database to be created without running Prisma. The file is based on the output of ``pg_dump --schema-only willa`` in a container after cleaning up the syntax a bit and grouping related elements. Adds a ``bin/dbinit`` script that can be run to create the initial database structure. Reorder the Dockerfile a bit to ensure files that are more likely to change are in the more outer layers. Ref: AP-412
c759c67 to
4ad31b6
Compare
|
Changes in v6:
|
Allows for the database to be created without running Prisma. The file is based on the output of
pg_dump --schema-only willain a developer container. I cleaned up the syntax a bit and grouped related elements.Adds a
bin/dbinitscript that can be run to create the initial database structure.Reorder the Dockerfile a bit to ensure files that are more likely to change are in the more outer layers.
Ref: AP-412
I'd prefer to land #74 first, but this should be the last actual requirement to a production deployment.
Tagging @danschmidt5189 for usability for the Docker build and the changes to the Dockerfile.