@@ -6,17 +6,12 @@ module.exports = {
66 async up ( queryInterface , Sequelize ) {
77 const transaction = await queryInterface . sequelize . transaction ( ) ;
88 try {
9- let created = new Set ( ) ;
10- const model_inventories_approver_org_ids = await queryInterface . sequelize . query ( `
11- SELECT mi.*, u.organization_id AS organization_id FROM
12- public.model_inventories AS mi INNER JOIN public.users AS u
13- ON mi.approver = u.id;
14- ` , { transaction } ) ;
15-
16- for ( const row of model_inventories_approver_org_ids [ 0 ] ) {
17- const tenantHash = getTenantHash ( row . organization_id ) ;
18- if ( ! created . has ( tenantHash ) ) {
19- await queryInterface . sequelize . query ( `
9+ const organizations = await queryInterface . sequelize . query (
10+ `SELECT id FROM organizations;` , { transaction }
11+ )
12+ for ( let organization of organizations [ 0 ] ) {
13+ const tenantHash = getTenantHash ( organization . id ) ;
14+ await queryInterface . sequelize . query ( `
2015 CREATE TABLE "${ tenantHash } ".model_inventories (
2116 id SERIAL PRIMARY KEY,
2217 provider_model VARCHAR(255) NOT NULL,
@@ -35,8 +30,16 @@ module.exports = {
3530 REFERENCES public.users (id) MATCH SIMPLE
3631 ON UPDATE NO ACTION ON DELETE SET NULL
3732 );` , { transaction } ) ;
38- created . add ( tenantHash ) ;
39- }
33+ }
34+
35+ const model_inventories_approver_org_ids = await queryInterface . sequelize . query ( `
36+ SELECT mi.*, u.organization_id AS organization_id FROM
37+ public.model_inventories AS mi INNER JOIN public.users AS u
38+ ON mi.approver = u.id;
39+ ` , { transaction } ) ;
40+
41+ for ( const row of model_inventories_approver_org_ids [ 0 ] ) {
42+ const tenantHash = getTenantHash ( row . organization_id ) ;
4043 await queryInterface . sequelize . query ( `
4144 INSERT INTO "${ tenantHash } ".model_inventories (
4245 provider_model,
0 commit comments