alfateam / orange-orm

The ultimate ORM for Node and Typescript
https://orange-orm.io
ISC License
675 stars 20 forks source link

what tools do you recommend for database migration ? #74

Closed francelwebdev closed 4 months ago

francelwebdev commented 8 months ago

what tools do you recommend for database migration ?

lroal commented 8 months ago

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 commented 7 months ago

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 commented 7 months ago

other simple tools ?

lroal commented 7 months ago

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 commented 6 months ago

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

lroal commented 6 months ago

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

lroal commented 4 months ago

@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. https://github.com/prisma/prisma/discussions/24290