File tree Expand file tree Collapse file tree
openops-tables/template-tables Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { getTableByName } from '@openops/common' ;
22import { logger } from '@openops/server-shared' ;
33import { FlagEntity } from '../../flags/flag.entity' ;
4- import { SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME } from '../../openops-tables/template-tables/create-auto-instances-shutdown-table' ;
5- import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates' ;
4+ import {
5+ createAutoInstancesShutdownTable ,
6+ SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME ,
7+ } from '../../openops-tables/template-tables/create-auto-instances-shutdown-table' ;
68import { databaseConnection } from '../database-connection' ;
79import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token' ;
10+ import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database' ;
811
912const AUTO_INSTANCES_SHUTDOWN_TABLE_SEED = 'AUTOINSTANCESSHUTDOWN' ;
1013
@@ -39,7 +42,8 @@ export const seedAutoInstancesShutdownTable = async (): Promise<void> => {
3942 ) ;
4043
4144 if ( ! table ) {
42- await seedTemplateTablesService . createAutoInstancesShutdownTable ( ) ;
45+ const tokenAndDatabaseId = await getAdminTokenAndDatabaseId ( ) ;
46+ await createAutoInstancesShutdownTable ( tokenAndDatabaseId ) ;
4347 }
4448
4549 await setTableSeedFlag ( ) ;
Original file line number Diff line number Diff line change 1+ import { AppSystemProp , system } from '@openops/server-shared' ;
2+ import { Project } from '@openops/shared' ;
3+ import { authenticateAdminUserInOpenOpsTables } from '../../openops-tables/auth-admin-tables' ;
4+ import { projectService } from '../../project/project-service' ;
5+ import { userService } from '../../user/user-service' ;
6+
7+ const getAdminUserProject = async ( ) : Promise < Project > => {
8+ const email = system . getOrThrow ( AppSystemProp . OPENOPS_ADMIN_EMAIL ) ;
9+ const user = await userService . getByOrganizationAndEmail ( {
10+ organizationId : null ,
11+ email,
12+ } ) ;
13+
14+ if ( ! user ) {
15+ throw new Error ( `Admin user not found for email: ${ email } ` ) ;
16+ }
17+
18+ const project = await projectService . getOneForUser ( user ) ;
19+
20+ if ( ! project ) {
21+ throw new Error ( `No project found for user: ${ email } ` ) ;
22+ }
23+
24+ return project ;
25+ } ;
26+
27+ export const getAdminTokenAndDatabaseId = async ( ) : Promise < {
28+ token : string ;
29+ tablesDatabaseId : number ;
30+ } > => {
31+ const { token } = await authenticateAdminUserInOpenOpsTables ( ) ;
32+ const { tablesDatabaseId } = await getAdminUserProject ( ) ;
33+ return { token, tablesDatabaseId } ;
34+ } ;
Original file line number Diff line number Diff line change 11import { getTableByName } from '@openops/common' ;
22import { logger } from '@openops/server-shared' ;
33import { FlagEntity } from '../../flags/flag.entity' ;
4- import { SEED_TABLE_NAME } from '../../openops-tables/template-tables/create-aggregated-costs-table' ;
5- import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates' ;
4+ import {
5+ createAggregatedCostsTable ,
6+ SEED_TABLE_NAME ,
7+ } from '../../openops-tables/template-tables/create-aggregated-costs-table' ;
68import { databaseConnection } from '../database-connection' ;
79import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token' ;
10+ import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database' ;
811
912const AGGREGATED_TABLE_SEED = 'AGGREGATEDCOSTS' ;
1013
@@ -38,7 +41,8 @@ export const seedFocusDataAggregationTemplateTable =
3841 ) ;
3942
4043 if ( ! table ) {
41- await seedTemplateTablesService . createAggregatedCostsTable ( ) ;
44+ const tokenAndDatabaseId = await getAdminTokenAndDatabaseId ( ) ;
45+ await createAggregatedCostsTable ( tokenAndDatabaseId ) ;
4246 }
4347
4448 await setTableSeedFlag ( ) ;
Original file line number Diff line number Diff line change 11import { getTableByName } from '@openops/common' ;
22import { logger } from '@openops/server-shared' ;
33import { FlagEntity } from '../../flags/flag.entity' ;
4- import { SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME } from '../../openops-tables/template-tables/create-known-cost-types-by-application-table' ;
5- import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates' ;
4+ import {
5+ createKnownCostTypesByApplicationTable ,
6+ SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME ,
7+ } from '../../openops-tables/template-tables/create-known-cost-types-by-application-table' ;
68import { databaseConnection } from '../database-connection' ;
79import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token' ;
10+ import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database' ;
811
912const KNOWN_COST_TYPES_BY_APPLICATION = 'KNOWNCOSTTYPES' ;
1013
@@ -39,7 +42,8 @@ export const seedKnownCostTypesByApplicationTable = async (): Promise<void> => {
3942 ) ;
4043
4144 if ( ! table ) {
42- await seedTemplateTablesService . createKnownCostTypesByApplicationTable ( ) ;
45+ const tokenAndDatabaseId = await getAdminTokenAndDatabaseId ( ) ;
46+ await createKnownCostTypesByApplicationTable ( tokenAndDatabaseId ) ;
4347 }
4448
4549 await setTableSeedFlag ( ) ;
Original file line number Diff line number Diff line change 11import { getTableByName } from '@openops/common' ;
22import { logger } from '@openops/server-shared' ;
33import { FlagEntity } from '../../flags/flag.entity' ;
4- import { SEED_OPENOPS_TABLE_NAME } from '../../openops-tables/template-tables/create-opportunities-table' ;
5- import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates' ;
4+ import {
5+ createOpportunitiesTable ,
6+ SEED_OPENOPS_TABLE_NAME ,
7+ } from '../../openops-tables/template-tables/create-opportunities-table' ;
68import { databaseConnection } from '../database-connection' ;
79import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token' ;
10+ import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database' ;
811
912const OPPORTUNITIES_TABLE_SEED = 'OPPORTUNITIESSEED' ;
1013
@@ -39,7 +42,8 @@ export const seedOpportunitesTemplateTable = async (): Promise<void> => {
3942 ) ;
4043
4144 if ( ! table ) {
42- await seedTemplateTablesService . createOpportunityTemplateTable ( ) ;
45+ const tokenAndDatabaseId = await getAdminTokenAndDatabaseId ( ) ;
46+ await createOpportunitiesTable ( tokenAndDatabaseId ) ;
4347 }
4448
4549 await setTableSeedFlag ( ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { logger } from '@openops/server-shared';
22import { FlagEntity } from '../../flags/flag.entity' ;
33import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates' ;
44import { databaseConnection } from '../database-connection' ;
5+ import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database' ;
56
67const TEMPLATE_TABLES_SEED = 'TEMPLATE_TABLES_SEED' ;
78
@@ -30,7 +31,8 @@ export const seedTemplateTables = async (): Promise<void> => {
3031 return ;
3132 }
3233
33- await seedTemplateTablesService . createBaseTemplateTables ( ) ;
34+ const tokenAndDatabaseId = await getAdminTokenAndDatabaseId ( ) ;
35+ await seedTemplateTablesService . createBaseTemplateTables ( tokenAndDatabaseId ) ;
3436
3537 await setTableSeedFlag ( ) ;
3638} ;
Original file line number Diff line number Diff line change @@ -7,18 +7,19 @@ import {
77} from '@openops/common' ;
88import { logger } from '@openops/server-shared' ;
99import { openopsTables } from '../index' ;
10+ import { TokenAndDatabaseId } from './types' ;
1011
1112export const SEED_TABLE_NAME = 'Aggregated Costs' ;
1213const SEED_LOG_HEADER = `[Seeding ${ SEED_TABLE_NAME } table]` ;
1314
14- export async function createAggregatedCostsTable (
15- databaseId : number ,
16- token : string ,
17- ) : Promise < { tableId : number } > {
15+ export async function createAggregatedCostsTable ( {
16+ token ,
17+ tablesDatabaseId ,
18+ } : TokenAndDatabaseId ) : Promise < { tableId : number } > {
1819 logger . debug ( `${ SEED_LOG_HEADER } Start` ) ;
1920
2021 const table = await openopsTables . createTable (
21- databaseId ,
22+ tablesDatabaseId ,
2223 SEED_TABLE_NAME ,
2324 [ [ 'Group Key' ] ] ,
2425 token ,
Original file line number Diff line number Diff line change @@ -7,20 +7,21 @@ import {
77} from '@openops/common' ;
88import { logger } from '@openops/server-shared' ;
99import { createTable } from '../create-table' ;
10+ import { TokenAndDatabaseId } from './types' ;
1011
1112export const SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME =
1213 'Auto instances shutdown' ;
1314
14- export async function createAutoInstancesShutdownTable (
15- token : string ,
16- databaseId : number ,
17- ) : Promise < void > {
15+ export async function createAutoInstancesShutdownTable ( {
16+ token,
17+ tablesDatabaseId ,
18+ } : TokenAndDatabaseId ) : Promise < void > {
1819 logger . debug (
1920 `[Seeding ${ SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME } table] Start` ,
2021 ) ;
2122
2223 const table = await createTable (
23- databaseId ,
24+ tablesDatabaseId ,
2425 SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME ,
2526 [ [ 'Resource ID' ] ] ,
2627 token ,
Original file line number Diff line number Diff line change @@ -8,20 +8,21 @@ import {
88} from '@openops/common' ;
99import { logger } from '@openops/server-shared' ;
1010import { createTable } from '../create-table' ;
11+ import { TokenAndDatabaseId } from './types' ;
1112
1213export const SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME =
1314 'Known cost types by application' ;
1415
15- export async function createKnownCostTypesByApplicationTable (
16- token : string ,
17- databaseId : number ,
18- ) {
16+ export async function createKnownCostTypesByApplicationTable ( {
17+ token,
18+ tablesDatabaseId ,
19+ } : TokenAndDatabaseId ) {
1920 logger . debug (
2021 `[Seeding ${ SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME } table] Start` ,
2122 ) ;
2223
2324 const table = await createTable (
24- databaseId ,
25+ tablesDatabaseId ,
2526 SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME ,
2627 [ [ 'ID' ] ] ,
2728 token ,
Original file line number Diff line number Diff line change @@ -8,17 +8,18 @@ import {
88} from '@openops/common' ;
99import { logger } from '@openops/server-shared' ;
1010import { createTable } from '../create-table' ;
11+ import { TokenAndDatabaseId } from './types' ;
1112
1213export const SEED_OPENOPS_TABLE_NAME = 'Opportunities' ;
1314
14- export async function createOpportunitiesTable (
15- token : string ,
16- databaseId : number ,
17- ) {
15+ export async function createOpportunitiesTable ( {
16+ token,
17+ tablesDatabaseId ,
18+ } : TokenAndDatabaseId ) {
1819 logger . debug ( `[Seeding ${ SEED_OPENOPS_TABLE_NAME } table] Start` ) ;
1920
2021 const table = await createTable (
21- databaseId ,
22+ tablesDatabaseId ,
2223 SEED_OPENOPS_TABLE_NAME ,
2324 [ [ 'ID' ] ] ,
2425 token ,
You can’t perform that action at this time.
0 commit comments