enhance: add updateAt column to query
This commit is contained in:
parent
9fefd93f09
commit
f1ed6d095a
3 changed files with 28 additions and 1 deletions
|
@ -50,6 +50,7 @@ import { CreateSchema1738166167472 } from "./migrations/1738166167472-CreateSche
|
|||
import { TemplatesAndProtocolSort1742549956787 } from "./migrations/1742549956787-templatesAndProtocolSort";
|
||||
import { QueryToUUID1742922178643 } from "./migrations/1742922178643-queryToUUID";
|
||||
import { NewsletterColumnType1744351418751 } from "./migrations/1744351418751-newsletterColumnType";
|
||||
import { QueryUpdatedAt1744795756230 } from "./migrations/1744795756230-QueryUpdatedAt";
|
||||
|
||||
const dataSource = new DataSource({
|
||||
type: DB_TYPE as any,
|
||||
|
@ -109,6 +110,7 @@ const dataSource = new DataSource({
|
|||
TemplatesAndProtocolSort1742549956787,
|
||||
QueryToUUID1742922178643,
|
||||
NewsletterColumnType1744351418751,
|
||||
QueryUpdatedAt1744795756230,
|
||||
],
|
||||
migrationsRun: true,
|
||||
migrationsTransactionMode: "each",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||
import { Column, Entity, PrimaryColumn, UpdateDateColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class query {
|
||||
|
@ -10,4 +10,7 @@ export class query {
|
|||
|
||||
@Column({ type: "text", default: "" })
|
||||
query: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
|
22
src/migrations/1744795756230-QueryUpdatedAt.ts
Normal file
22
src/migrations/1744795756230-QueryUpdatedAt.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||
import { getTypeByORM, getDefaultByORM } from "./ormHelper";
|
||||
|
||||
export class QueryUpdatedAt1744795756230 implements MigrationInterface {
|
||||
name = "QueryUpdatedAt1744795756230";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.addColumn(
|
||||
"query",
|
||||
new TableColumn({
|
||||
name: "updatedAt",
|
||||
...getTypeByORM("datetime", false, 6),
|
||||
default: getDefaultByORM("currentTimestamp", 6),
|
||||
onUpdate: getDefaultByORM<string>("currentTimestamp", 6),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropColumn("query", "updatedAt");
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue