Skip to content
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

Add migrations to web db #2233

Merged
merged 2 commits into from
Mar 26, 2023
Merged

Add migrations to web db #2233

merged 2 commits into from
Mar 26, 2023

Conversation

AbdBarho
Copy link
Collaborator

@AbdBarho AbdBarho commented Mar 26, 2023

We fucked up real bad here:

We started using prisma db push to sync the prisma schema with the db, with the intention of moving to migrations "soon":

# This docker file will update the web database with schema changes. Later it
# will be updated to do prisma migrations.
FROM --platform=linux/amd64 node:16.18.0 AS runner
WORKDIR /app
COPY ./website/ .
CMD ["npx", "prisma", "db", "push"]

But we never did this (because we never needed it), now I wanted to add a new table to the database and realized that the infrastructure for something like this is not in place.

Here I created an initial migration from the already available db scheme, to be able to deploy this without losing any data, we would need to force prisma to mark this migration as applied (even though it is not)

The command is as follows:

npx prisma migrate resolve --applied 20230326131923_initial_migration

So this means, we have to ssh into the production web container and run this command to have the ability to apply future migrations.

All the changes to the schema.prisma file are auto-formatting by the prisma vscode extension

@LAION-AI LAION-AI deleted a comment from github-actions bot Mar 26, 2023
@AbdBarho AbdBarho marked this pull request as ready for review March 26, 2023 14:18
@AbdBarho AbdBarho requested a review from notmd as a code owner March 26, 2023 14:18
@notmd
Copy link
Collaborator

notmd commented Mar 26, 2023

What happens when you add a new table and run prisma db push? I thought it just work, although we cant rollback the table.

@AbdBarho
Copy link
Collaborator Author

What happens when you add a new table and run prisma db push? I thought it just work, although we cant rollback the table.

it works if all you do is add new tables or columns, but it is not safe, prisma will push everything and drop tables if necessary. i.e. data loss.

@notmd notmd merged commit 5f74c3e into main Mar 26, 2023
@notmd notmd deleted the web-db branch March 26, 2023 15:34
AbdBarho added a commit that referenced this pull request Apr 7, 2023
Follow up to #2233 

* update website container to include migrations
* remove outdated prisma container
* update other containers for better layer caching.

This PR contains no behavioural changes.

More context:

We started using `prisma db push` to sync our web db prisma schema with
the db, with the intention of moving to migrations soon™, but we never
did this because we never needed it.

Now I wanted to add a new table to the database and realized that the
infrastructure for something like this is not in place.

I created an initial migration from the already available db scheme, to
be able to deploy this without losing any data, we would need to force
prisma to mark this migration as applied.

The command is as follows:
```
npx prisma migrate resolve --applied 20230326131923_initial_migration
```

This PR prepare the web docker container to have migrations as a first
class citizen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants