Skip to content

Commit

Permalink
Issue #3200 Add grant_notes and grant_notes_revisions table migration (
Browse files Browse the repository at this point in the history
…#3209)

* Create migration to add grant_notes and grant_notes_revisions tables

* Create migration to add grant_notes and grant_notes_revisions tables

* Add useConstraint modifier to the creation of the unique index.

Knex documentation says for the unique() function, that useConstraint will use a unique constraint and is default true for postgres when there is no predicate defined.
Issue #3200 specifies that we want a unique index.
Documentation can be found here: https://knexjs.org/guide/schema-builder.html#unique

* Lint
  • Loading branch information
thucdtran authored Jul 1, 2024
1 parent 8f34a01 commit af7e14f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/server/migrations/20240622205204_add-grant-notes-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema
.createTable('grant_notes', (table) => {
table.increments('id').notNullable().primary();
table.text('grant_id').notNullable();
table.integer('user_id').notNullable();
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now());

table.foreign('grant_id').references('grants.grant_id');
table.foreign('user_id').references('users.id');

table.unique(['grant_id', 'user_id'], {
indexName: 'idx_grant_id_user_id',
useConstraint: false,
});
})
.createTable('grant_notes_revisions', (table) => {
table.increments('id').notNullable().primary();
table.integer('grant_note_id').notNullable();
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(knex.fn.now());
table.text('text').notNullable();
table.foreign('grant_note_id').references('grant_notes.id');
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable('grant_notes')
.dropTable('grant_notes_revisions');
};

0 comments on commit af7e14f

Please sign in to comment.