B
B
Bogdan2019-10-21 21:59:13
Node.js
Bogdan, 2019-10-21 21:59:13

Migrations for raw requests?

Hello. Tell me please. Base on PostreSQL. I used to use Sequelize, but in migrations I write raw queries

const tableName = 'Roles';

module.exports = {
  up: ({ sequelize }) => sequelize.query(`
    CREATE TABLE "${tableName}" (
      id SERIAL PRIMARY KEY,
      name VARCHAR(40) NOT NULL DEFAULT '',
      "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
      "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
    );

    CREATE TRIGGER "${tableName}UpdateAt"
      BEFORE UPDATE ON "${tableName}"
        FOR EACH ROW EXECUTE PROCEDURE "updateAtTimestamp"();

    INSERT INTO "${tableName}" (name)
      VALUES ('admin'), ('trader'), ('dealer'), ('customer');
  `),
  down: ({ sequelize }) => sequelize.query(`DROP TABLE IF EXISTS "${tableName}";`)
};

Maybe there is some simpler tool for migrations, otherwise pulling sequelize into the project seems like an overhead. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2019-10-21
@Sanasol

Why do you need some tool if you write raw queries?
It can still use what the tool gives , and not write queries by hand (why did they set the ORM at all then?)
https://sequelize.org/v5/manual/migrations.html#mi...

A
Alexey P, 2019-10-22
@ruddy22

knex.js - good replacement for Sequelize (+ easy to debug)
+ db-migrate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question