Skip to content

Commit 1b1bfcb

Browse files
authored
Further refactor template tables seed for improved semantics (#1726)
Part of OPS-3009.
1 parent 804eb47 commit 1b1bfcb

13 files changed

Lines changed: 42 additions & 46 deletions

packages/server/api/src/app/database/seeds/auto-instances-shutdown-table-seed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../openops-tables/template-tables/create-auto-instances-shutdown-table';
88
import { databaseConnection } from '../database-connection';
99
import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token';
10-
import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database';
10+
import { getAdminTablesContext } from './get-admin-token-and-database';
1111

1212
const AUTO_INSTANCES_SHUTDOWN_TABLE_SEED = 'AUTOINSTANCESSHUTDOWN';
1313

@@ -42,8 +42,8 @@ export const seedAutoInstancesShutdownTable = async (): Promise<void> => {
4242
);
4343

4444
if (!table) {
45-
const tokenAndDatabaseId = await getAdminTokenAndDatabaseId();
46-
await createAutoInstancesShutdownTable(tokenAndDatabaseId);
45+
const tablesContext = await getAdminTablesContext();
46+
await createAutoInstancesShutdownTable(tablesContext);
4747
}
4848

4949
await setTableSeedFlag();

packages/server/api/src/app/database/seeds/get-admin-token-and-database.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AppSystemProp, system } from '@openops/server-shared';
22
import { Project } from '@openops/shared';
33
import { authenticateAdminUserInOpenOpsTables } from '../../openops-tables/auth-admin-tables';
4+
import { TablesContext } from '../../openops-tables/template-tables/types';
45
import { projectService } from '../../project/project-service';
56
import { userService } from '../../user/user-service';
67

@@ -24,10 +25,7 @@ const getAdminUserProject = async (): Promise<Project> => {
2425
return project;
2526
};
2627

27-
export const getAdminTokenAndDatabaseId = async (): Promise<{
28-
token: string;
29-
tablesDatabaseId: number;
30-
}> => {
28+
export const getAdminTablesContext = async (): Promise<TablesContext> => {
3129
const { token } = await authenticateAdminUserInOpenOpsTables();
3230
const { tablesDatabaseId } = await getAdminUserProject();
3331
return { token, tablesDatabaseId };

packages/server/api/src/app/database/seeds/openops-aggregated-costs-seed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../openops-tables/template-tables/create-aggregated-costs-table';
88
import { databaseConnection } from '../database-connection';
99
import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token';
10-
import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database';
10+
import { getAdminTablesContext } from './get-admin-token-and-database';
1111

1212
const AGGREGATED_TABLE_SEED = 'AGGREGATEDCOSTS';
1313

@@ -41,8 +41,8 @@ export const seedFocusDataAggregationTemplateTable =
4141
);
4242

4343
if (!table) {
44-
const tokenAndDatabaseId = await getAdminTokenAndDatabaseId();
45-
await createAggregatedCostsTable(tokenAndDatabaseId);
44+
const tablesContext = await getAdminTablesContext();
45+
await createAggregatedCostsTable(tablesContext);
4646
}
4747

4848
await setTableSeedFlag();

packages/server/api/src/app/database/seeds/openops-knonw-cost-types-by-application-seed.ts renamed to packages/server/api/src/app/database/seeds/openops-known-cost-types-by-application-seed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../openops-tables/template-tables/create-known-cost-types-by-application-table';
88
import { databaseConnection } from '../database-connection';
99
import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token';
10-
import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database';
10+
import { getAdminTablesContext } from './get-admin-token-and-database';
1111

1212
const KNOWN_COST_TYPES_BY_APPLICATION = 'KNOWNCOSTTYPES';
1313

@@ -42,8 +42,8 @@ export const seedKnownCostTypesByApplicationTable = async (): Promise<void> => {
4242
);
4343

4444
if (!table) {
45-
const tokenAndDatabaseId = await getAdminTokenAndDatabaseId();
46-
await createKnownCostTypesByApplicationTable(tokenAndDatabaseId);
45+
const tablesContext = await getAdminTablesContext();
46+
await createKnownCostTypesByApplicationTable(tablesContext);
4747
}
4848

4949
await setTableSeedFlag();

packages/server/api/src/app/database/seeds/openops-opportunities-table-seed.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../openops-tables/template-tables/create-opportunities-table';
88
import { databaseConnection } from '../database-connection';
99
import { getDefaultProjectTablesDatabaseToken } from '../get-default-user-db-token';
10-
import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database';
10+
import { getAdminTablesContext } from './get-admin-token-and-database';
1111

1212
const OPPORTUNITIES_TABLE_SEED = 'OPPORTUNITIESSEED';
1313

@@ -42,8 +42,8 @@ export const seedOpportunitesTemplateTable = async (): Promise<void> => {
4242
);
4343

4444
if (!table) {
45-
const tokenAndDatabaseId = await getAdminTokenAndDatabaseId();
46-
await createOpportunitiesTable(tokenAndDatabaseId);
45+
const tablesContext = await getAdminTablesContext();
46+
await createOpportunitiesTable(tablesContext);
4747
}
4848

4949
await setTableSeedFlag();

packages/server/api/src/app/database/seeds/seed-template-tables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { logger } from '@openops/server-shared';
22
import { FlagEntity } from '../../flags/flag.entity';
3-
import { seedTemplateTablesService } from '../../openops-tables/template-tables/seed-tables-for-templates';
3+
import { createBaseTemplateTables } from '../../openops-tables/template-tables/seed-tables-for-templates';
44
import { databaseConnection } from '../database-connection';
5-
import { getAdminTokenAndDatabaseId } from './get-admin-token-and-database';
5+
import { getAdminTablesContext } from './get-admin-token-and-database';
66

77
const TEMPLATE_TABLES_SEED = 'TEMPLATE_TABLES_SEED';
88

@@ -31,8 +31,8 @@ export const seedTemplateTables = async (): Promise<void> => {
3131
return;
3232
}
3333

34-
const tokenAndDatabaseId = await getAdminTokenAndDatabaseId();
35-
await seedTemplateTablesService.createBaseTemplateTables(tokenAndDatabaseId);
34+
const tablesContext = await getAdminTablesContext();
35+
await createBaseTemplateTables(tablesContext);
3636

3737
await setTableSeedFlag();
3838
};

packages/server/api/src/app/openops-tables/template-tables/create-aggregated-costs-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import {
77
} from '@openops/common';
88
import { logger } from '@openops/server-shared';
99
import { openopsTables } from '../index';
10-
import { TokenAndDatabaseId } from './types';
10+
import { TablesContext } from './types';
1111

1212
export const SEED_TABLE_NAME = 'Aggregated Costs';
1313
const SEED_LOG_HEADER = `[Seeding ${SEED_TABLE_NAME} table]`;
1414

1515
export async function createAggregatedCostsTable({
1616
token,
1717
tablesDatabaseId,
18-
}: TokenAndDatabaseId): Promise<{ tableId: number }> {
18+
}: TablesContext): Promise<{ tableId: number }> {
1919
logger.debug(`${SEED_LOG_HEADER} Start`);
2020

2121
const table = await openopsTables.createTable(

packages/server/api/src/app/openops-tables/template-tables/create-auto-instances-shutdown-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import {
77
} from '@openops/common';
88
import { logger } from '@openops/server-shared';
99
import { createTable } from '../create-table';
10-
import { TokenAndDatabaseId } from './types';
10+
import { TablesContext } from './types';
1111

1212
export const SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME =
1313
'Auto instances shutdown';
1414

1515
export async function createAutoInstancesShutdownTable({
1616
token,
1717
tablesDatabaseId,
18-
}: TokenAndDatabaseId): Promise<void> {
18+
}: TablesContext): Promise<void> {
1919
logger.debug(
2020
`[Seeding ${SEED_OPENOPS_AUTO_INSTANCES_SHUTDOWN_TABLE_NAME} table] Start`,
2121
);

packages/server/api/src/app/openops-tables/template-tables/create-known-cost-types-by-application-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import {
88
} from '@openops/common';
99
import { logger } from '@openops/server-shared';
1010
import { createTable } from '../create-table';
11-
import { TokenAndDatabaseId } from './types';
11+
import { TablesContext } from './types';
1212

1313
export const SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME =
1414
'Known cost types by application';
1515

1616
export async function createKnownCostTypesByApplicationTable({
1717
token,
1818
tablesDatabaseId,
19-
}: TokenAndDatabaseId) {
19+
}: TablesContext) {
2020
logger.debug(
2121
`[Seeding ${SEED_OPENOPS_KNOWN_COST_TYPES_BY_APPLICATION_TABLE_NAME} table] Start`,
2222
);

packages/server/api/src/app/openops-tables/template-tables/create-opportunities-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import {
88
} from '@openops/common';
99
import { logger } from '@openops/server-shared';
1010
import { createTable } from '../create-table';
11-
import { TokenAndDatabaseId } from './types';
11+
import { TablesContext } from './types';
1212

1313
export const SEED_OPENOPS_TABLE_NAME = 'Opportunities';
1414

1515
export async function createOpportunitiesTable({
1616
token,
1717
tablesDatabaseId,
18-
}: TokenAndDatabaseId) {
18+
}: TablesContext) {
1919
logger.debug(`[Seeding ${SEED_OPENOPS_TABLE_NAME} table] Start`);
2020

2121
const table = await createTable(

0 commit comments

Comments
 (0)