mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
chore(schemas): fix alteration timestamp (#5645)
chore(schemas): fix alteration scripts order
This commit is contained in:
parent
66abc50c6c
commit
bf471e1451
1 changed files with 43 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
||||||
|
import { sql } from '@silverhand/slonik';
|
||||||
|
|
||||||
|
import type { AlterationScript } from '../lib/types/alteration.js';
|
||||||
|
|
||||||
|
import { applyTableRls } from './utils/1704934999-tables.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The script `next-1711955211-organization-resource-scope` was merged after `next-1712041436-rename-organization-member-role-to-collaborator`,
|
||||||
|
* so the table `organization_role_resource_scope_relations` may not be created in the database.
|
||||||
|
* This script is to fix the issue, try to create the table if it is not exists.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const alteration: AlterationScript = {
|
||||||
|
up: async (pool) => {
|
||||||
|
const result = await pool.maybeOne(sql`
|
||||||
|
select * from information_schema.tables
|
||||||
|
where table_name = 'organization_role_resource_scope_relations'
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// The table already exists, do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await pool.query(sql`
|
||||||
|
create table organization_role_resource_scope_relations (
|
||||||
|
tenant_id varchar(21) not null
|
||||||
|
references tenants (id) on update cascade on delete cascade,
|
||||||
|
organization_role_id varchar(21) not null
|
||||||
|
references organization_roles (id) on update cascade on delete cascade,
|
||||||
|
scope_id varchar(21) not null
|
||||||
|
references scopes (id) on update cascade on delete cascade,
|
||||||
|
primary key (tenant_id, organization_role_id, scope_id)
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
await applyTableRls(pool, 'organization_role_resource_scope_relations');
|
||||||
|
},
|
||||||
|
down: async () => {
|
||||||
|
// Do nothing
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default alteration;
|
Loading…
Reference in a new issue