-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-service/database/migrations): professor_disponibilidade and …
…turma_disponibilidade
- Loading branch information
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...tions/database/typeorm/migrations/1733495227008-create-table-professor-disponibilidade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { MigrationInterface, QueryRunner, Table } from "typeorm"; | ||
|
||
const tableName = "professor_disponibilidade"; | ||
|
||
export class CreateTableDisponibilidadeDia1733495227008 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: tableName, | ||
|
||
columns: [ | ||
{ | ||
name: "id", | ||
type: "uuid", | ||
isPrimary: true, | ||
default: "gen_random_uuid()", | ||
}, | ||
// | ||
{ | ||
name: "id_disponibilidade_fk", | ||
type: "uuid", | ||
isNullable: false, | ||
}, | ||
// | ||
{ | ||
name: "id_perfil_fk", | ||
type: "uuid", | ||
isNullable: false, | ||
}, | ||
// | ||
{ | ||
name: "date_created", | ||
type: "timestamptz", | ||
isNullable: false, | ||
default: "NOW()", | ||
}, | ||
{ | ||
name: "date_updated", | ||
type: "timestamptz", | ||
isNullable: false, | ||
default: "NOW()", | ||
}, | ||
|
||
{ | ||
name: "date_deleted", | ||
type: "timestamptz", | ||
isNullable: true, | ||
}, | ||
// | ||
], | ||
foreignKeys: [ | ||
{ | ||
name: `fk__${tableName}__depende__perfil`, | ||
columnNames: ["id_perfil_fk"], | ||
referencedColumnNames: ["id"], | ||
referencedTableName: "perfil", | ||
}, | ||
{ | ||
name: `fk__${tableName}__depende__disponibilidade`, | ||
columnNames: ["id_disponibilidade_fk"], | ||
referencedColumnNames: ["id"], | ||
referencedTableName: "disponibilidade", | ||
}, | ||
], | ||
}), | ||
); | ||
|
||
await queryRunner.query(` | ||
CREATE TRIGGER change_date_updated_table_${tableName} | ||
BEFORE UPDATE ON ${tableName} | ||
FOR EACH ROW | ||
EXECUTE FUNCTION change_date_updated(); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable(tableName, true, true, true); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...egrations/database/typeorm/migrations/1733495227009-create-table-turma-disponibilidade.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { MigrationInterface, QueryRunner, Table } from "typeorm"; | ||
|
||
const tableName = "turma_disponibilidade"; | ||
|
||
export class CreateTableDisponibilidadeDia1733495227009 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: tableName, | ||
|
||
columns: [ | ||
{ | ||
name: "id", | ||
type: "uuid", | ||
isPrimary: true, | ||
default: "gen_random_uuid()", | ||
}, | ||
// | ||
{ | ||
name: "id_disponibilidade_fk", | ||
type: "uuid", | ||
isNullable: false, | ||
}, | ||
// | ||
{ | ||
name: "id_turma_fk", | ||
type: "uuid", | ||
isNullable: false, | ||
}, | ||
// | ||
{ | ||
name: "date_created", | ||
type: "timestamptz", | ||
isNullable: false, | ||
default: "NOW()", | ||
}, | ||
{ | ||
name: "date_updated", | ||
type: "timestamptz", | ||
isNullable: false, | ||
default: "NOW()", | ||
}, | ||
|
||
{ | ||
name: "date_deleted", | ||
type: "timestamptz", | ||
isNullable: true, | ||
}, | ||
// | ||
], | ||
foreignKeys: [ | ||
{ | ||
name: `fk__${tableName}__depende__turma`, | ||
columnNames: ["id_turma_fk"], | ||
referencedColumnNames: ["id"], | ||
referencedTableName: "turma", | ||
}, | ||
{ | ||
name: `fk__${tableName}__depende__disponibilidade`, | ||
columnNames: ["id_disponibilidade_fk"], | ||
referencedColumnNames: ["id"], | ||
referencedTableName: "disponibilidade", | ||
}, | ||
], | ||
}), | ||
); | ||
|
||
await queryRunner.query(` | ||
CREATE TRIGGER change_date_updated_table_${tableName} | ||
BEFORE UPDATE ON ${tableName} | ||
FOR EACH ROW | ||
EXECUTE FUNCTION change_date_updated(); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable(tableName, true, true, true); | ||
} | ||
} |