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

[fix] Migrations #763

Open
wants to merge 18 commits into
base: v3
Choose a base branch
from
Open

Conversation

marvin-wtt
Copy link

Description:

This PR restructures the migration process to avoid issues where migrations were updated after they’ve already been applied. Updating migrations late leads to failures when running clean migrations, breaking database consistency.

Changes:

  • Moved existing migrations from the models directory to a dedicated migrations directory.
  • Removed duplicate migrations and existence checks

Note:

This PR is based of #762

@marvin-wtt marvin-wtt changed the base branch from develop to v3 September 14, 2024 00:08
@poeti8
Copy link
Member

poeti8 commented Sep 15, 2024

See this commit, this fixes the issue where knex was looking for the previous .ts files to verify the migration: 9d9f57a

But regarding the migration files, this is how I see them: Keep the current migration files intact. Create new migration files for all the changes you want to make. Edit the models if necessary, this way it's clear what the final form of a model is by looking at that model file. The changes to the models are only applied when Kutt is running for the first time, otherwise, the changes are ignored and applied through the migration files.

@marvin-wtt
Copy link
Author

But regarding the migration files, this is how I see them: Keep the current migration files intact. Create new migration files for all the changes you want to make. Edit the models if necessary, this way it's clear what the final form of a model is by looking at that model file. The changes to the models are only applied when Kutt is running for the first time, otherwise, the changes are ignored and applied through the migration files.

The migration files that were already run should never be executed again by knex. Only new migrations are being executed. All successful migrations are stored in the DB. What I did is revert the migration files to the state before they were applied. All changes were then kept in their respective migration files without the checks, as they are not needed. Just keeping it like this is very bad practice and cause trouble with fresh installations as the migrations are not sequentially. For all existing installations, the changes have no effect as the migrations won't be run again.

@marvin-wtt
Copy link
Author

See this commit, this fixes the issue where knex was looking for the previous .ts files to verify the migration: 9d9f57a

Are you sure that this is enough? I think all existing migrations are still considered "new" by knex as the file extension is stored in the migrations table too.

As already mentioned, I don't see any benefits of dropping TS, but it causes trouble like this. I can offer to create a PR and revert the latest v3 back to TS and rebase the PRs, but that's of course your decision.

# Conflicts:
#	server/models/index.js
#	server/queries/link.queries.js
@poeti8
Copy link
Member

poeti8 commented Sep 15, 2024

Are you sure that this is enough? I think all existing migrations are still considered "new" by knex as the file extension is stored in the migrations table too.

Yes, because the migrations mostly check if the changes are already done or not. For example they only create tables if they have not already been created.

As already mentioned, I don't see any benefits of dropping TS, but it causes trouble like this. I can offer to create a PR and revert the latest v3 back to TS and rebase the PRs, but that's of course your decision.

No, I still prefer no TypeScript for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants