-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
feat: add migration #8891
base: main
Are you sure you want to change the base?
feat: add migration #8891
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files |
Notable changes:
|
@@ -43,12 +48,30 @@ beforeAll(async () => { | |||
|
|||
await app.linkProjectToEnvironment('default', 'development'); | |||
|
|||
await stores.accessStore.addPermissionsToRole( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we were enabling feature in development and it requires two permissions. Previously they were present from a default migration that adds permissions to default, development and production envs. However we delete all environments now and all role permissions are gone. We restore all 15 permissions for the default env but for all envs that we create explicitly in tests we need to add permissions explicitly
{ name: UPDATE_FEATURE_ENVIRONMENT }, | ||
{ name: CREATE_FEATURE_STRATEGY }, | ||
], | ||
'production', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the previous comment for development
@@ -110,15 +120,20 @@ export default async function init( | |||
const testDb = createDb(config); | |||
const stores = await createStores(config, testDb); | |||
stores.eventStore.setMaxListeners(0); | |||
const defaultRolePermissions = await getDefaultEnvRolePermissions(testDb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the main fix. Read all env permissions for the default environment
await resetDatabase(testDb); | ||
await setupDatabase(stores); | ||
await restoreRolePermissions(testDb, defaultRolePermissions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-apply the permissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One alternative solution would be to store all 15 permissions in a file. What are the tradeoffs?
- with DB query and insert approach our tests are verifying actual permissions in migrations
- one drawback of DB query and insert is that it's different from all the other data that we seed from database.json
@@ -94,8 +94,6 @@ const createRole = async (rolePermissions: PermissionRef[]) => { | |||
|
|||
const hasCommonProjectAccess = async (user, projectName, condition) => { | |||
const defaultEnv = 'default'; | |||
const developmentEnv = 'development'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those 2 environments were tested directly against user permissions table that has changes and when we delete development and production in DB seed we also loose role permissions for those two environments
@@ -637,15 +571,15 @@ test('should support permission with "ALL" environment requirement', async () => | |||
await accessStore.addPermissionsToRole( | |||
customRole.id, | |||
[{ name: CREATE_FEATURE_STRATEGY }], | |||
'production', | |||
'default', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the env that we actually have in tests
Creates a data migration that allows us to remove all hanging permissions tied to deleted environments. In addition, this migration adds a foreign key relationship to environment column that references environments name. See rationale here.