Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

what tools do you recommend for database migration ? #74

Closed
francelwebdev opened this issue Feb 1, 2024 · 7 comments
Closed

what tools do you recommend for database migration ? #74

francelwebdev opened this issue Feb 1, 2024 · 7 comments

Comments

@francelwebdev
Copy link

what tools do you recommend for database migration ?

@lroal
Copy link
Member

lroal commented Feb 2, 2024

Personally, I prefer to roll my own - and not use any external tools.
I manually create the migration scripts and name them something like 001_initial_schema.sql and 002_add_users_table.sql.

Then I create a small node program or bash script that runs each script in a transaction.
To keep track of which script is run, you need to add db_version table with the last run script to check against.

CREATE TABLE IF NOT EXISTS db_version (
            id SERIAL PRIMARY KEY,
            script_name VARCHAR(255) NOT NULL,
            executed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
        );

I will come back with a complete running example later this week or early next week.
Maybe I should add it to the documentation as well.

If you prefer an external tool, you could use Liquibase or Flyway.
However, these tools require Java. I use Liquibase at my current job. But this is mainly because we are in a mixed environment with Java already. We would probably not use it in a pure node environment.

@lroal
Copy link
Member

lroal commented Feb 23, 2024

I promised to give you a full example. But then I got the flu or something and was unable to work. I will come back to you.

@francelwebdev
Copy link
Author

other simple tools ?

@lroal
Copy link
Member

lroal commented Feb 24, 2024

There is something called db-migrate, but you still have to write manual sql.

I have never tested it. But it has a reasonable amount of downloads and latest release on npm was 6 months ago.

@francelwebdev
Copy link
Author

Hi @lroal ,
what do your think about this migration tool (https://github.com/shahriarKabir44/migratify) for mysql ?

@lroal
Copy link
Member

lroal commented Mar 29, 2024

The migration tool you're looking at might not be the best choice because:

  • It uses local log files to track migrations, which can get messy if you're working in a team or on different machines. It also means that it can only support one single database (excluding separate environments for development, staging and production)
  • Very few people are using it, so there's not much proof it works well or support if you run into issues.
  • There's no github actions for automatic testing. Without tests, it's hard to trust that the tool won't break something.
  • There are no changelog or issues

@lroal
Copy link
Member

lroal commented May 27, 2024

@francelwebdev What if you could generate a prisma schema via command cli ?
Then you could use prisma for the migrations.
At least as a temporary solution.
prisma/prisma#24290

@alfateam alfateam locked and limited conversation to collaborators May 27, 2024
@lroal lroal converted this issue into discussion #89 May 27, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants