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

migrations: convert some from knex to raw SQL #1085

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/model/migrations/20171023-01-authz-forms.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
// Copyright 2017 ODK Central Developers
// Copyright 2024 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
//
const up = (knex) =>
knex.schema.table('forms', (forms) => {
forms.string('acteeId', 36).notNull();
forms.foreign('acteeId').references('actees.id');
});

const down = (knex) =>
knex.schema.table('forms', (forms) => forms.dropColumn('acteeId'));

module.exports = { up, down };

module.exports = {
down: () => { throw new Error('down() not yet supported for this migration'); },
up: async (db) => {
await db.raw(`alter table "forms" add column "acteeId" varchar(36) not null`);
await db.raw(`alter table "forms" add constraint "forms_acteeid_foreign" foreign key ("acteeId") references "actees" ("id")`);
},
};
16 changes: 7 additions & 9 deletions lib/model/migrations/20171106-01-remove-user-update-timestamp.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright 2017 ODK Central Developers
// Copyright 2024 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
//
const up = (knex) =>
knex.schema.table('users', (users) => users.dropColumn('updatedAt'));

const down = (knex) =>
knex.schema.table('users', (users) => users.dateTime('updatedAt'));

module.exports = { up, down };

module.exports = {
down: () => { throw new Error('down() not yet supported for this migration'); },
up: async (db) => {
await db.raw(`alter table "users" drop column "updatedAt"`);
},
};
18 changes: 7 additions & 11 deletions lib/model/migrations/20171121-01-add-submissions-constraint.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// Copyright 2017 ODK Central Developers
// Copyright 2024 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
//
const up = (knex) =>
knex.schema.table('submissions', (submissions) =>
submissions.unique([ 'formId', 'instanceId' ]));

const down = (knex) =>
knex.schema.table('submissions', (submissions) =>
submissions.dropUnique([ 'formId', 'instanceId' ]));

module.exports = { up, down };

module.exports = {
down: () => { throw new Error('down() not yet supported for this migration'); },
up: async (db) => {
await db.raw(`alter table "submissions" add constraint "submissions_formid_instanceid_unique" unique ("formId", "instanceId")`);
},
};
22 changes: 8 additions & 14 deletions lib/model/migrations/20171121-02-add-submitter.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// Copyright 2017 ODK Central Developers
// Copyright 2024 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
//
const up = (knex) =>
knex.schema.table('submissions', (submissions) => {
submissions.integer('submitter');
submissions.foreign('submitter').references('actors.id');
});

const down = (knex) =>
knex.schema.table('submissions', (submissions) =>
submissions.dropColumn('submitter'));

module.exports = { up, down };


module.exports = {
down: () => { throw new Error('down() not yet supported for this migration'); },
up: async (db) => {
await db.raw(`alter table "submissions" add column "submitter" integer`);
await db.raw(`alter table "submissions" add constraint "submissions_submitter_foreign" foreign key ("submitter") references "actors" ("id")`);
},
};
18 changes: 9 additions & 9 deletions lib/model/migrations/20171213-01-unrequire-display-name.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2017 ODK Central Developers
// Copyright 2024 ODK Central Developers
// See the NOTICE file at the top-level directory of this distribution and at
// https://github.com/getodk/central-backend/blob/master/NOTICE.
// This file is part of ODK Central. It is subject to the license terms in
// the LICENSE file found in the top-level directory of this distribution and at
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
// including this file, may be copied, modified, propagated, or distributed
// except according to the terms contained in the LICENSE file.
//
const up = (knex) =>
knex.schema.table('actors', (actors) => actors.string('displayName', 64).nullable().alter());

const down = (knex) =>
knex.schema.table('actors', (actors) => actors.string('displayName', 64).notNullable().alter());

module.exports = { up, down };

module.exports = {
down: () => { throw new Error('down() not yet supported for this migration'); },
up: async (db) => {
await db.raw(`alter table "actors" alter column "displayName" drop default`);
await db.raw(`alter table "actors" alter column "displayName" drop not null`);
await db.raw(`alter table "actors" alter column "displayName" type varchar(64) using ("displayName"::varchar(64))`);
},
};