mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-18 13:48:58 +02:00
fix: add down migration, remaining fixes
This commit is contained in:
parent
f780391b44
commit
a81b3853cd
@ -123,7 +123,7 @@ export class AccessStore implements IAccessStore {
|
||||
let userPermissionQuery = this.db
|
||||
.select(
|
||||
'project',
|
||||
'permission',
|
||||
'rp.permission',
|
||||
'environment',
|
||||
'type',
|
||||
'ur.role_id',
|
||||
@ -136,7 +136,7 @@ export class AccessStore implements IAccessStore {
|
||||
userPermissionQuery = userPermissionQuery.union((db) => {
|
||||
db.select(
|
||||
'project',
|
||||
'permission',
|
||||
'rp.permission',
|
||||
'environment',
|
||||
'p.type',
|
||||
'gr.role_id',
|
||||
@ -152,7 +152,7 @@ export class AccessStore implements IAccessStore {
|
||||
userPermissionQuery = userPermissionQuery.union((db) => {
|
||||
db.select(
|
||||
this.db.raw("'default' as project"),
|
||||
'permission',
|
||||
'rp.permission',
|
||||
'environment',
|
||||
'p.type',
|
||||
'g.root_role_id as role_id',
|
||||
@ -198,7 +198,7 @@ export class AccessStore implements IAccessStore {
|
||||
const stopTimer = this.timer('getPermissionsForRole');
|
||||
const rows = await this.db
|
||||
.select(
|
||||
'p.permission',
|
||||
'rp.permission',
|
||||
'rp.environment',
|
||||
'p.display_name',
|
||||
'p.type',
|
||||
|
@ -90,7 +90,7 @@ test('should complete environment field of permissions when not present', async
|
||||
description: 'description',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'name',
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -101,7 +101,7 @@ test('should complete environment field of permissions when not present', async
|
||||
description: 'description',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'name',
|
||||
environment: '',
|
||||
},
|
||||
],
|
||||
@ -116,7 +116,7 @@ test('should return the same object when all fields are valid and present', asyn
|
||||
description: 'description',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'name',
|
||||
environment: 'development',
|
||||
},
|
||||
],
|
||||
@ -126,7 +126,7 @@ test('should return the same object when all fields are valid and present', asyn
|
||||
description: 'description',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'name',
|
||||
environment: 'development',
|
||||
},
|
||||
],
|
||||
@ -141,7 +141,6 @@ test('should be able to validate and cleanup with additional properties', async
|
||||
additional: 'property',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
environment: 'development',
|
||||
name: 'name',
|
||||
displayName: 'displayName',
|
||||
@ -155,7 +154,6 @@ test('should be able to validate and cleanup with additional properties', async
|
||||
description: 'description',
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'name',
|
||||
environment: 'development',
|
||||
},
|
||||
|
@ -79,7 +79,7 @@ SELECT * FROM (VALUES
|
||||
('UPDATE_FRONTEND_API_TOKEN', 'Update FRONTEND API tokens', 'root'),
|
||||
('DELETE_FRONTEND_API_TOKEN', 'Delete FRONTEND API tokens', 'root'),
|
||||
('READ_FRONTEND_API_TOKEN', 'Read FRONTEND API tokens', 'root'),
|
||||
('UPDATE_FEATURE_DEPENDENCY', 'Update feature dependency', 'project')
|
||||
('UPDATE_FEATURE_DEPENDENCY', 'Update feature dependency', 'project'),
|
||||
('CREATE_TAG_TYPE', 'Create tag types', 'root')
|
||||
) AS new_permissions(permission, display_name, type)
|
||||
WHERE NOT EXISTS (
|
||||
@ -90,6 +90,39 @@ WHERE NOT EXISTS (
|
||||
);
|
||||
};
|
||||
|
||||
exports.down = function (db, callback) {
|
||||
callback();
|
||||
exports.down = function (db, cb) {
|
||||
db.runSql(
|
||||
`
|
||||
-- STEP 1: Undo foreign key constraint on 'role_permission'
|
||||
ALTER TABLE role_permission
|
||||
DROP CONSTRAINT fk_role_permission_permission;
|
||||
|
||||
-- STEP 2: Undo primary key constraint on 'permissions'
|
||||
ALTER TABLE permissions
|
||||
DROP CONSTRAINT permissions_pkey;
|
||||
|
||||
-- STEP 3: Re-add the permissions 'id' column
|
||||
ALTER TABLE permissions
|
||||
ADD COLUMN id SERIAL PRIMARY KEY;
|
||||
|
||||
-- STEP 4: Re-add the role_permission 'permission_id' column
|
||||
ALTER TABLE role_permission
|
||||
ADD COLUMN permission_id INTEGER;
|
||||
|
||||
-- STEP 5: Re-add the permissions
|
||||
UPDATE role_permission rp
|
||||
SET permission_id = p.id
|
||||
FROM permissions p
|
||||
WHERE rp.permission = p.permission;
|
||||
|
||||
-- STEP 6: Drop the new 'permission' column
|
||||
ALTER TABLE role_permission
|
||||
DROP COLUMN permission;
|
||||
|
||||
-- STEP 7: Drop the unique constraint on 'permission'
|
||||
ALTER TABLE permissions
|
||||
DROP CONSTRAINT permission_unique;
|
||||
`,
|
||||
cb
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user