Skip to content

Commit

Permalink
refactor: table name and schema name enums
Browse files Browse the repository at this point in the history
  • Loading branch information
QuaidBartolomei committed Mar 6, 2022
1 parent e98cada commit 479a15d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 15 additions & 9 deletions .jest/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
12 changes: 11 additions & 1 deletion server/infra/database/knex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -31,3 +36,8 @@ export const enum TableNames {
Countries = 'region',
RegionType = 'region_type',
}

export const enum WalletTables {
Wallet = 'wallet',
Token = 'token',
}

0 comments on commit 479a15d

Please sign in to comment.