Skip to content

Commit

Permalink
Move migration and seed-data folder
Browse files Browse the repository at this point in the history
  • Loading branch information
aberonni committed May 30, 2024
1 parent 0c57223 commit 7d6f1a7
Show file tree
Hide file tree
Showing 236 changed files with 127 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_service_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Check that no new migrations are necessary
working-directory: ./services
run: |
docker compose exec 121-service npm run migration:generate migration/irrelevant_file_name -- --check
docker compose exec 121-service npm run migration:generate src/migration/irrelevant_file_name -- --check
- name: Run API tests with Jest
working-directory: ./services
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ When making changes to the data-model of the `121-service` (creating/editing any
The process is:

1. Make the changes in the `\*.entity.ts` file
2. To generate a migration-script run: `docker exec 121-service npm run migration:generate migration/<descriptive-name-for-migration-script>`. This will compare the data-model according to your code with the data-model according to your database, and generate any CREATE, ALTER, etc SQL-statements that are needed to make the database align with code again.
2. To generate a migration-script run: `docker exec 121-service npm run migration:generate src/migration/<descriptive-name-for-migration-script>`. This will compare the data-model according to your code with the data-model according to your database, and generate any CREATE, ALTER, etc SQL-statements that are needed to make the database align with code again.
3. Restart the 121-service through `docker restart 121-service`: this will always run any new migration-scripts (and thus update the data-model in the database), so in this case the just generated migration-script.
4. If more changes required, then follow the above process as often as needed.
5. Do NOT import any files from our code base into your migrations. For example, do NOT import seed JSON files to get data to insert into the database, since the migration may break if ever these seed JSON files change. Instead, "hard code" the needed data in your migration file.
Expand All @@ -180,7 +180,7 @@ The process is:

NOTE: if you're making many data-model changes at once, or are doing a lot of trial and error, there is an alternative option:

1. In `services/121-service/ormconfig.js` set `synchronize` to `true` and restart `121-service`.
1. In `services/121-service/src/ormconfig.ts` set `synchronize` to `true` and restart `121-service`.
2. This will make sure that any changes you make to `\*.entity.ts` files are automatically updated in your database tables, which allows for quicker development/testing.
3. When you're done with all your changes, you will need to revert all changes temporarily to be able to create a migration script. There are multiple ways to do this, for example by stashing all your changes, or working with a new branch, etc. Either way:
- stashing all your changes (git stash)
Expand Down Expand Up @@ -231,7 +231,7 @@ If there are issues with Docker commands, it could be due to permissions. Prefix

If the errors are related to not being able to access/connect to the database then reset/recreate the database by:

- Setting `dropSchema: true` in `ormconfig.ts` of the specific service.
- Setting `dropSchema: true` in `src/ormconfig.ts` of the specific service.
- Restarting that service will reset/recreate its database(-schema)

### Upgrade Node.js version
Expand Down
7 changes: 6 additions & 1 deletion services/121-service/.knip.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"$schema": "node_modules/knip/schema.json",
"entry": ["index.js"],
"project": ["src/**/*.{js,ts}", "!src/**/*.spec.{js,ts}"],
"project": [
"src/**/*.{js,ts}",
"!src/**/*.spec.{js,ts}",
"!src/migration/**/*.{js,ts}",
"!src/seed-data/**/*.{js,ts}"
],
"rules": {
"dependencies": "warn",
"devDependencies": "warn",
Expand Down
6 changes: 3 additions & 3 deletions services/121-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"test:e2e:coverage": "npm run test:e2e:all -- --coverage --coverageDirectory=coverage/e2e",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"migration:create": "npm run typeorm migration:create --",
"migration:generate": "npm run typeorm migration:generate -- -d ./appdatasource.ts",
"migration:run": "npm run typeorm migration:run -- -d ./appdatasource.ts",
"migration:revert": "npm run typeorm migration:revert -- -d ./appdatasource.ts",
"migration:generate": "npm run typeorm migration:generate -- -d ./src/appdatasource.ts",
"migration:run": "npm run typeorm migration:run -- -d ./src/appdatasource.ts",
"migration:revert": "npm run typeorm migration:revert -- -d ./src/appdatasource.ts",
"knip": "knip",
"knip:fix": "knip --fix-type files,exports,types"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ORMConfig } from '@121-service/ormconfig';
import { ORMConfig } from '@121-service/src/ormconfig';
import { DataSource, DataSourceOptions } from 'typeorm';
export const AppDataSource = new DataSource(ORMConfig as DataSourceOptions);
2 changes: 1 addition & 1 deletion services/121-service/src/base.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppDataSource } from '@121-service/appdatasource';
import { AppDataSource } from '@121-service/src/appdatasource';
import {
CreateDateColumn,
Index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ORMConfig: DataSourceOptions = {
entities: ['src/**/**.entity.ts'],
subscribers: ['src/**/**.subscriber.ts'],
migrationsTableName: 'custom_migration_table',
migrations: ['migration/*.ts'],
migrations: ['src/migration/*.ts'],
migrationsRun: false,
dropSchema: false,
synchronize: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ImageCodeService {
code: string;
pin: string;
}): Promise<Buffer> {
const voucherBaseFile = './seed-data/voucher/ah-voucher_base.png';
const voucherBaseFile = './src/seed-data/voucher/ah-voucher_base.png';
const barcodeImage = await this.generateBarCodeImage(voucherData.code);

// See Jimp documentation: https://www.npmjs.com/package/jimp/v/0.16.1
Expand Down
2 changes: 1 addition & 1 deletion services/121-service/src/programs/program.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppDataSource } from '@121-service/appdatasource';
import { ActionEntity } from '@121-service/src/actions/action.entity';
import { AppDataSource } from '@121-service/src/appdatasource';
import { CascadeDeleteEntity } from '@121-service/src/base.entity';
import { FinancialServiceProviderEntity } from '@121-service/src/financial-service-providers/financial-service-provider.entity';
import { MessageTemplateEntity } from '@121-service/src/notifications/message-template/message-template.entity';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppDataSource } from '@121-service/appdatasource';
import { AppDataSource } from '@121-service/src/appdatasource';
import { InstanceEntity } from '@121-service/src/instance/instance.entity';
import { ProgramEntity } from '@121-service/src/programs/program.entity';
import { RegistrationDataByNameDto } from '@121-service/src/registration/dto/registration-data-by-name.dto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppDataSource } from '@121-service/appdatasource';
import { AppDataSource } from '@121-service/src/appdatasource';
import { Base121Entity } from '@121-service/src/base.entity';
import { FspQuestionEntity } from '@121-service/src/financial-service-providers/fsp-question.entity';
import { ProgramCustomAttributeEntity } from '@121-service/src/programs/program-custom-attribute.entity';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AppDataSource } from '@121-service/appdatasource';
import { AppDataSource } from '@121-service/src/appdatasource';
import { ProgramAidworkerAssignmentEntity } from '@121-service/src/programs/program-aidworker.entity';
import { RegistrationEntity } from '@121-service/src/registration/registration.entity';
import { RegistrationDataTypeClassValidator } from '@121-service/src/registration/validators/registration-data-type.class.validator';
import { Repository } from 'typeorm';

jest.mock('../../../appdatasource', () => ({
jest.mock('../../appdatasource', () => ({
AppDataSource: {
getRepository: {
findOne: jest.fn().mockResolvedValue(null),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppDataSource } from '@121-service/appdatasource';
import { AppDataSource } from '@121-service/src/appdatasource';
import { ProgramAidworkerAssignmentEntity } from '@121-service/src/programs/program-aidworker.entity';
import { CreateRegistrationDto } from '@121-service/src/registration/dto/create-registration.dto';
import { Attributes } from '@121-service/src/registration/dto/update-registration.dto';
Expand Down
2 changes: 1 addition & 1 deletion services/121-service/src/scripts/scripts.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ORMConfig } from '@121-service/ormconfig';
import { MessageTemplateModule } from '@121-service/src/notifications/message-template/message-template.module';
import { ORMConfig } from '@121-service/src/ormconfig';
import { ProgramModule } from '@121-service/src/programs/programs.module';
import { QueueSeedHelperModule } from '@121-service/src/scripts/queue-seed-helper/queue-seed-helper.module';
import { ScriptsController } from '@121-service/src/scripts/scripts.controller';
Expand Down
14 changes: 7 additions & 7 deletions services/121-service/src/scripts/seed-eth-joint-response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import instanceEthJointResponse from '@121-service/seed-data/instance/instance-eth-joint-response.json';
import messageTemplateAne from '@121-service/seed-data/message-template/message-template-joint-response-ANE.json';
import messageTemplateEKHCDC from '@121-service/seed-data/message-template/message-template-joint-response-EKHCDC.json';
import messageTemplateDorcas from '@121-service/seed-data/message-template/message-template-joint-response-dorcas.json';
import programAne from '@121-service/seed-data/program/program-joint-response-ANE.json';
import programEKHCDC from '@121-service/seed-data/program/program-joint-response-EKHCDC.json';
import programDorcas from '@121-service/seed-data/program/program-joint-response-dorcas.json';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instanceEthJointResponse from '@121-service/src/seed-data/instance/instance-eth-joint-response.json';
import messageTemplateAne from '@121-service/src/seed-data/message-template/message-template-joint-response-ANE.json';
import messageTemplateEKHCDC from '@121-service/src/seed-data/message-template/message-template-joint-response-EKHCDC.json';
import messageTemplateDorcas from '@121-service/src/seed-data/message-template/message-template-joint-response-dorcas.json';
import programAne from '@121-service/src/seed-data/program/program-joint-response-ANE.json';
import programEKHCDC from '@121-service/src/seed-data/program/program-joint-response-EKHCDC.json';
import programDorcas from '@121-service/src/seed-data/program/program-joint-response-dorcas.json';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand Down
30 changes: 15 additions & 15 deletions services/121-service/src/scripts/seed-init.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import fspAfricasTalking from '@121-service/seed-data/fsp/fsp-africas-talking.json';
import fspBank from '@121-service/seed-data/fsp/fsp-bank.json';
import fspBelcash from '@121-service/seed-data/fsp/fsp-belcash.json';
import fspBob from '@121-service/seed-data/fsp/fsp-bob.json';
import fspCommercialBankEthiopia from '@121-service/seed-data/fsp/fsp-commercial-bank-ethiopia.json';
import fspExcel from '@121-service/seed-data/fsp/fsp-excel.json';
import fspIntersolveJumboPhysical from '@121-service/seed-data/fsp/fsp-intersolve-jumbo-physical.json';
import fspIntersolveVisa from '@121-service/seed-data/fsp/fsp-intersolve-visa.json';
import fspIntersolveVoucherPaper from '@121-service/seed-data/fsp/fsp-intersolve-voucher-paper.json';
import fspIntersolveVoucher from '@121-service/seed-data/fsp/fsp-intersolve-voucher-whatsapp.json';
import fspMixedAttributes from '@121-service/seed-data/fsp/fsp-mixed-attributes.json';
import fspNoAttributes from '@121-service/seed-data/fsp/fsp-no-attributes.json';
import fspSafaricom from '@121-service/seed-data/fsp/fsp-safaricom.json';
import fspUkrPoshta from '@121-service/seed-data/fsp/fsp-ukrposhta.json';
import fspVodaCash from '@121-service/seed-data/fsp/fsp-vodacash.json';
import { QueueSeedHelperService } from '@121-service/src/scripts/queue-seed-helper/queue-seed-helper.service';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import fspAfricasTalking from '@121-service/src/seed-data/fsp/fsp-africas-talking.json';
import fspBank from '@121-service/src/seed-data/fsp/fsp-bank.json';
import fspBelcash from '@121-service/src/seed-data/fsp/fsp-belcash.json';
import fspBob from '@121-service/src/seed-data/fsp/fsp-bob.json';
import fspCommercialBankEthiopia from '@121-service/src/seed-data/fsp/fsp-commercial-bank-ethiopia.json';
import fspExcel from '@121-service/src/seed-data/fsp/fsp-excel.json';
import fspIntersolveJumboPhysical from '@121-service/src/seed-data/fsp/fsp-intersolve-jumbo-physical.json';
import fspIntersolveVisa from '@121-service/src/seed-data/fsp/fsp-intersolve-visa.json';
import fspIntersolveVoucherPaper from '@121-service/src/seed-data/fsp/fsp-intersolve-voucher-paper.json';
import fspIntersolveVoucher from '@121-service/src/seed-data/fsp/fsp-intersolve-voucher-whatsapp.json';
import fspMixedAttributes from '@121-service/src/seed-data/fsp/fsp-mixed-attributes.json';
import fspNoAttributes from '@121-service/src/seed-data/fsp/fsp-no-attributes.json';
import fspSafaricom from '@121-service/src/seed-data/fsp/fsp-safaricom.json';
import fspUkrPoshta from '@121-service/src/seed-data/fsp/fsp-ukrposhta.json';
import fspVodaCash from '@121-service/src/seed-data/fsp/fsp-vodacash.json';
import { CustomHttpService } from '@121-service/src/shared/services/custom-http.service';
import { PermissionEnum } from '@121-service/src/user/enum/permission.enum';
import { PermissionEntity } from '@121-service/src/user/permissions.entity';
Expand Down
14 changes: 7 additions & 7 deletions services/121-service/src/scripts/seed-multiple-krcs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import instanceKRCS from '@121-service/seed-data/instance/instance-krcs.json';
import messageTemplateBaringo from '@121-service/seed-data/message-template/message-template-krcs-baringo.json';
import messageTemplateTurkana from '@121-service/seed-data/message-template/message-template-krcs-turkana.json';
import messageTemplateWestPokot from '@121-service/seed-data/message-template/message-template-krcs-westpokot.json';
import programBaringo from '@121-service/seed-data/program/program-krcs-baringo.json';
import programTurkana from '@121-service/seed-data/program/program-krcs-turkana.json';
import programWestPokot from '@121-service/seed-data/program/program-krcs-westpokot.json';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instanceKRCS from '@121-service/src/seed-data/instance/instance-krcs.json';
import messageTemplateBaringo from '@121-service/src/seed-data/message-template/message-template-krcs-baringo.json';
import messageTemplateTurkana from '@121-service/src/seed-data/message-template/message-template-krcs-turkana.json';
import messageTemplateWestPokot from '@121-service/src/seed-data/message-template/message-template-krcs-westpokot.json';
import programBaringo from '@121-service/src/seed-data/program/program-krcs-baringo.json';
import programTurkana from '@121-service/src/seed-data/program/program-krcs-turkana.json';
import programWestPokot from '@121-service/src/seed-data/program/program-krcs-westpokot.json';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand Down
10 changes: 5 additions & 5 deletions services/121-service/src/scripts/seed-multiple-nlrc-mock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { registrationAHWhatsapp } from '@121-service/seed-data/mock/registration-pv.data';
import {
amountVisa,
registrationVisa,
} from '@121-service/seed-data/mock/visa-card.data';
import { RegistrationStatusEnum } from '@121-service/src/registration/enum/registration-status.enum';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedMockHelper } from '@121-service/src/scripts/seed-mock-helpers';
import { SeedMultipleNLRC } from '@121-service/src/scripts/seed-multiple-nlrc';
import { registrationAHWhatsapp } from '@121-service/src/seed-data/mock/registration-pv.data';
import {
amountVisa,
registrationVisa,
} from '@121-service/src/seed-data/mock/visa-card.data';
import { AxiosCallsService } from '@121-service/src/utils/axios/axios-calls.service';
import { waitFor } from '@121-service/src/utils/waitFor.helper';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
Expand Down
10 changes: 5 additions & 5 deletions services/121-service/src/scripts/seed-multiple-nlrc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import instanceNLRC from '@121-service/seed-data/instance/instance-nlrc.json';
import messageTemplateOCW from '@121-service/seed-data/message-template/message-template-nlrc-ocw.json';
import messageTemplatePV from '@121-service/seed-data/message-template/message-template-nlrc-pv.json';
import programOCW from '@121-service/seed-data/program/program-nlrc-ocw.json';
import programPV from '@121-service/seed-data/program/program-nlrc-pv.json';
import { DebugScope } from '@121-service/src/scripts/enum/debug-scope.enum';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instanceNLRC from '@121-service/src/seed-data/instance/instance-nlrc.json';
import messageTemplateOCW from '@121-service/src/seed-data/message-template/message-template-nlrc-ocw.json';
import messageTemplatePV from '@121-service/src/seed-data/message-template/message-template-nlrc-pv.json';
import programOCW from '@121-service/src/seed-data/program/program-nlrc-ocw.json';
import programPV from '@121-service/src/seed-data/program/program-nlrc-pv.json';
import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';

Expand Down
6 changes: 3 additions & 3 deletions services/121-service/src/scripts/seed-program-demo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import instanceDemo from '@121-service/seed-data/instance/instance-demo.json';
import messageTemplateDemo from '@121-service/seed-data/message-template/message-template-demo.json';
import programDemo from '@121-service/seed-data/program/program-demo.json';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instanceDemo from '@121-service/src/seed-data/instance/instance-demo.json';
import messageTemplateDemo from '@121-service/src/seed-data/message-template/message-template-demo.json';
import programDemo from '@121-service/src/seed-data/program/program-demo.json';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions services/121-service/src/scripts/seed-program-drc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import instanceDrc from '@121-service/seed-data/instance/instance-drc.json';
import messageTemplateDrc from '@121-service/seed-data/message-template/message-template-drc.json';
import programDrc from '@121-service/seed-data/program/program-drc.json';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instanceDrc from '@121-service/src/seed-data/instance/instance-drc.json';
import messageTemplateDrc from '@121-service/src/seed-data/message-template/message-template-drc.json';
import programDrc from '@121-service/src/seed-data/program/program-drc.json';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand Down
6 changes: 3 additions & 3 deletions services/121-service/src/scripts/seed-program-eth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import instancePilotEth from '@121-service/seed-data/instance/instance-pilot-eth.json';
import messageTemplatePilotEth from '@121-service/seed-data/message-template/message-template-pilot-zoa-eth.json';
import programPilotEth from '@121-service/seed-data/program/program-pilot-zoa-eth.json';
import { ProgramEntity } from '@121-service/src/programs/program.entity';
import { InterfaceScript } from '@121-service/src/scripts/scripts.module';
import { SeedHelper } from '@121-service/src/scripts/seed-helper';
import instancePilotEth from '@121-service/src/seed-data/instance/instance-pilot-eth.json';
import messageTemplatePilotEth from '@121-service/src/seed-data/message-template/message-template-pilot-zoa-eth.json';
import programPilotEth from '@121-service/src/seed-data/program/program-pilot-zoa-eth.json';
import { PermissionEnum } from '@121-service/src/user/enum/permission.enum';
import { PermissionEntity } from '@121-service/src/user/permissions.entity';
import { UserRoleEntity } from '@121-service/src/user/user-role.entity';
Expand Down
Loading

0 comments on commit 7d6f1a7

Please sign in to comment.