Skip to content

Commit

Permalink
Remove project_id from collections and workbooks tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sjorobekov committed Jan 17, 2025
1 parent 7071dd4 commit 112376b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ export async function up(knex: Knex): Promise<void> {
return knex.raw(`
DROP INDEX collections_uniq_title_idx;
DROP INDEX workbooks_uniq_title_idx;
DROP INDEX workbooks_project_id_idx;
ALTER TABLE workbooks DROP COLUMN project_id;
DROP INDEX collections_project_id_idx;
ALTER TABLE collections DROP COLUMN project_id;
Expand All @@ -18,40 +13,21 @@ export async function up(knex: Knex): Promise<void> {
title_lower
)
WHERE deleted_at IS NULL;
CREATE UNIQUE INDEX workbooks_uniq_title_idx
ON workbooks (
COALESCE(collection_id::text, tenant_id),
title_lower
)
WHERE deleted_at IS NULL;
`);
}

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
DROP INDEX collections_uniq_title_idx;
DROP INDEX workbooks_uniq_title_idx;
ALTER TABLE collections ADD COLUMN project_id TEXT DEFAULT NULL;
CREATE INDEX collections_project_id_idx ON collections USING BTREE (project_id);
ALTER TABLE workbooks ADD COLUMN project_id TEXT;
CREATE INDEX workbooks_project_id_idx ON workbooks USING BTREE (project_id);
CREATE UNIQUE INDEX collections_uniq_title_idx
ON collections (
COALESCE(parent_id::text, project_id, tenant_id),
title_lower
)
WHERE deleted_at IS NULL;
CREATE UNIQUE INDEX workbooks_uniq_title_idx
ON workbooks (
COALESCE(collection_id::text, project_id, tenant_id),
title_lower
)
WHERE deleted_at IS NULL;
`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {Knex} from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.raw(`
DROP INDEX workbooks_uniq_title_idx;
DROP INDEX workbooks_project_id_idx;
ALTER TABLE workbooks DROP COLUMN project_id;
CREATE UNIQUE INDEX workbooks_uniq_title_idx
ON workbooks (
COALESCE(collection_id::text, tenant_id),
title_lower
)
WHERE deleted_at IS NULL;
`);
}

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
DROP INDEX workbooks_uniq_title_idx;
ALTER TABLE workbooks ADD COLUMN project_id TEXT;
CREATE INDEX workbooks_project_id_idx ON workbooks USING BTREE (project_id);
CREATE UNIQUE INDEX workbooks_uniq_title_idx
ON workbooks (
COALESCE(collection_id::text, project_id, tenant_id),
title_lower
)
WHERE deleted_at IS NULL;
`);
}

0 comments on commit 112376b

Please sign in to comment.