diff --git a/nivel-02/02-iniciando-back-end-do-app/ormconfig.json b/nivel-02/02-iniciando-back-end-do-app/ormconfig.json index 5ab114c..0b51e34 100644 --- a/nivel-02/02-iniciando-back-end-do-app/ormconfig.json +++ b/nivel-02/02-iniciando-back-end-do-app/ormconfig.json @@ -4,5 +4,11 @@ "port": 5432, "username": "docker", "password": "docker", - "database": "gostack_gobarber" + "database": "gostack_gobarber", + "migrations": [ + "./src/database/migrations/*.ts" + ], + "cli": { + "migrationsDir": "./src/database/migrations" + } } diff --git a/nivel-02/02-iniciando-back-end-do-app/package.json b/nivel-02/02-iniciando-back-end-do-app/package.json index 4072eae..f13a383 100644 --- a/nivel-02/02-iniciando-back-end-do-app/package.json +++ b/nivel-02/02-iniciando-back-end-do-app/package.json @@ -5,7 +5,8 @@ "license": "MIT", "scripts": { "build": "tsc", - "dev:server": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/server.ts" + "dev:server": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/server.ts", + "typeorm": "ts-node-dev ./node_modules/typeorm/cli.js" }, "dependencies": { "date-fns": "^2.16.1", diff --git a/nivel-02/02-iniciando-back-end-do-app/src/database/migrations/1601469847641-CreateAppointments.ts b/nivel-02/02-iniciando-back-end-do-app/src/database/migrations/1601469847641-CreateAppointments.ts new file mode 100644 index 0000000..5b76275 --- /dev/null +++ b/nivel-02/02-iniciando-back-end-do-app/src/database/migrations/1601469847641-CreateAppointments.ts @@ -0,0 +1,34 @@ +import { MigrationInterface, QueryRunner, Table } from 'typeorm'; + +export default class CreateAppointments1601469847641 + implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: 'appointments', + columns: [ + { + name: 'id', + type: 'varchar', + isPrimary: true, + generationStrategy: 'uuid', + }, + { + name: 'provider', + type: 'varchar', + isNullable: false, + }, + { + name: 'date', + type: 'timestamp with time zone', + isNullable: false, + }, + ], + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropTable('appointments'); + } +}