-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): tenanted assets (#3206)
* feat(backend): migration to backfill tenantId on assets * feat(backend): add tenantId to asset, use it in service * feat(backend): use tenantId in asset resolvers * test(backend): update tests to use asset tenantId where necessary * test(backend): truncate tenant table manually in tenant tests * test(backend): update failing accounting tests * test(backend): update tenant service test * test: fix accounting tests linting * test(backend): update accounting tests * feat(backend): use tenantId when fetching asset * test(backend): make tests work with separate middleware * test(backend): keep operator tenant when truncating tables * test(backend): skip tenant pagination tests for now * test(backend): seed operator tenant in truncateTable * test(backend): seed operator tenant after tenants service is done * test(backend): use separate schema for tenant tests * test(backend): pass operator tenant id in pagination tests * feat(backend): make tenantId required in asset pagination * test(backend): update tenant service tests * chore(backend): update config file * test: update truncateTables to take in dbSchema * feat(backend): make tenantId optional in asset pagination
- Loading branch information
Showing
21 changed files
with
474 additions
and
185 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/backend/migrations/20241216160130_backfill_tenant_on_assets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return knex.schema | ||
.alterTable('assets', (table) => { | ||
table.uuid('tenantId').references('tenants.id').index() | ||
}) | ||
.then(() => { | ||
return knex.raw( | ||
`UPDATE "assets" SET "tenantId" = (SELECT id from "tenants" LIMIT 1)` | ||
) | ||
}) | ||
.then(() => { | ||
return knex.schema.alterTable('assets', (table) => { | ||
table.uuid('tenantId').notNullable().alter() | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.alterTable('assets', (table) => { | ||
table.dropColumn('tenantId') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.