feat(sprint3): migrations Sprint3Economy + fix data-source migrations path
- Create src/database/migrations/1742169600000-Sprint3Economy.ts
Tables : tetard_coins, tc_transactions, processed_events (IF NOT EXISTS)
- Fix migrations path : src/migrations/*.ts → __dirname/migrations/*{.ts,.js}
Fonctionne en ts-node (src/) et après build (dist/)
This commit is contained in:
@@ -35,6 +35,6 @@ export const AppDataSource = new DataSource({
|
||||
CraftJob,
|
||||
Monster,
|
||||
],
|
||||
migrations: ['src/migrations/*.ts'],
|
||||
migrations: [__dirname + '/migrations/*{.ts,.js}'],
|
||||
synchronize: false,
|
||||
});
|
||||
|
||||
44
src/database/migrations/1742169600000-Sprint3Economy.ts
Normal file
44
src/database/migrations/1742169600000-Sprint3Economy.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class Sprint3Economy1742169600000 implements MigrationInterface {
|
||||
name = 'Sprint3Economy1742169600000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`tetard_coins\` (
|
||||
\`id\` VARCHAR(36) NOT NULL,
|
||||
\`user_id\` VARCHAR(255) NOT NULL,
|
||||
\`balance\` INT NOT NULL DEFAULT 0,
|
||||
\`updated_at\` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE INDEX \`IDX_tetard_coins_user_id\` (\`user_id\`)
|
||||
) ENGINE=InnoDB
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`tc_transactions\` (
|
||||
\`id\` VARCHAR(36) NOT NULL,
|
||||
\`user_id\` VARCHAR(255) NOT NULL,
|
||||
\`amount\` INT NOT NULL,
|
||||
\`reason\` VARCHAR(100) NOT NULL,
|
||||
\`created_at\` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (\`id\`),
|
||||
INDEX \`IDX_tc_transactions_user_id\` (\`user_id\`)
|
||||
) ENGINE=InnoDB
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`processed_events\` (
|
||||
\`id\` VARCHAR(255) NOT NULL,
|
||||
\`processed_at\` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS \`processed_events\``);
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS \`tc_transactions\``);
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS \`tetard_coins\``);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user