From 479a15d7f223c0bb67518afe55af103126892e3a Mon Sep 17 00:00:00 2001 From: Quaid Bartolomei Date: Sat, 5 Mar 2022 16:59:09 -0800 Subject: [PATCH] refactor: table name and schema name enums --- .jest/globalSetup.ts | 24 +++++++++++++++--------- server/infra/database/knex.ts | 12 +++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.jest/globalSetup.ts b/.jest/globalSetup.ts index 46a15d76..3fbfda79 100644 --- a/.jest/globalSetup.ts +++ b/.jest/globalSetup.ts @@ -9,18 +9,24 @@ import country from '@seeds/data/country.json'; import organization from '@seeds/data/organization.json'; import token from '@seeds/data/token.json'; import regionType from '@seeds/data/region_type.json'; -import knex, { TableNames } from 'infra/database/knex'; +import knex, { + PublicTables, + SchemaNames, + WalletTables, +} from 'infra/database/knex'; export default async function globalSetup() { if (process.env.SEED === 'true') { - await knex(TableNames.Trees).insert(tree); - await knex('wallet').withSchema('wallet').insert(wallet); - await knex('token').withSchema('wallet').insert(token); - await knex(TableNames.Species).insert(species); - await knex(TableNames.Organizations).insert(organization); - await knex(TableNames.Planters).insert(planter); - await knex(TableNames.RegionType).insert(regionType); - await knex(TableNames.Countries).insert(country); + await knex(PublicTables.Trees).insert(tree); + await knex(WalletTables.Wallet) + .withSchema(SchemaNames.Wallet) + .insert(wallet); + await knex(WalletTables.Token).withSchema(SchemaNames.Wallet).insert(token); + await knex(PublicTables.Species).insert(species); + await knex(PublicTables.Organizations).insert(organization); + await knex(PublicTables.Planters).insert(planter); + await knex(PublicTables.RegionType).insert(regionType); + await knex(PublicTables.Countries).insert(country); } knex.destroy(); } diff --git a/server/infra/database/knex.ts b/server/infra/database/knex.ts index 8f2c73e7..6b1a1d0a 100644 --- a/server/infra/database/knex.ts +++ b/server/infra/database/knex.ts @@ -22,7 +22,12 @@ log.debug(knexConfig.searchPath); export default knex(knexConfig); -export const enum TableNames { +export const enum SchemaNames { + Public = 'public', + Wallet = 'wallet', +} + +export const enum PublicTables { Trees = 'trees', Wallets = 'wallet', Species = 'tree_species', @@ -31,3 +36,8 @@ export const enum TableNames { Countries = 'region', RegionType = 'region_type', } + +export const enum WalletTables { + Wallet = 'wallet', + Token = 'token', +}