diff --git a/src/migration/entities/migration.entity.ts b/src/migration/entities/migration.entity.ts new file mode 100644 index 0000000..5076631 --- /dev/null +++ b/src/migration/entities/migration.entity.ts @@ -0,0 +1,26 @@ +import { Project } from "src/project/entities/project.entity"; +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("migration") +export class Migration { + @PrimaryGeneratedColumn("uuid") + id: string; + + @Column() + name: string; + + @Column({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" }) + appliedAt: Date; + + @Column({ type: "tinyint", default: 1 }) + isApplied: number; + + @Column({ type: "tinyint", default: 1 }) + isValid: number; + + @ManyToOne(() => Project, (project) => project.migrations) + project: Project; + + @Column({ type: "jsonb", nullable: true }) + data: Record; +} diff --git a/src/migration/migration.constants.ts b/src/migration/migration.constants.ts new file mode 100644 index 0000000..b170d9b --- /dev/null +++ b/src/migration/migration.constants.ts @@ -0,0 +1,26 @@ +export type MigrationFieldType = + | "int" + | "float" + | "bigint" + | "boolean" + | "text" + | "uuid" + | "datetime"; + +export type MigrationField = { + type: MigrationFieldType; + isNullable: boolean; + isUnique: boolean; + default?: any; +}; + +export type MigrationRelationType = + | "one-to-many" + | "many-to-one" + | "many-to-many"; + +export type MigrationTable = { + name: string; + fields: Record; + relations?: Record; +}; diff --git a/src/migration/migration.controller.ts b/src/migration/migration.controller.ts new file mode 100644 index 0000000..6959a17 --- /dev/null +++ b/src/migration/migration.controller.ts @@ -0,0 +1,4 @@ +import { Controller } from "@nestjs/common"; + +@Controller("migrations") +export class MigrationController {} diff --git a/src/migration/migration.module.ts b/src/migration/migration.module.ts new file mode 100644 index 0000000..3725257 --- /dev/null +++ b/src/migration/migration.module.ts @@ -0,0 +1,12 @@ +import { Module } from "@nestjs/common"; +import { TypeOrmModule } from "@nestjs/typeorm"; +import { Migration } from "./entities/migration.entity"; +import { MigrationController } from "./migration.controller"; +import { MigrationService } from "./migration.service"; + +@Module({ + imports: [TypeOrmModule.forFeature([Migration])], + controllers: [MigrationController], + providers: [MigrationService], +}) +export class MigrationModule {} diff --git a/src/migration/migration.service.ts b/src/migration/migration.service.ts new file mode 100644 index 0000000..5869626 --- /dev/null +++ b/src/migration/migration.service.ts @@ -0,0 +1,27 @@ +import { Injectable } from "@nestjs/common"; +import { In, Repository } from "typeorm"; +import { Migration } from "./entities/migration.entity"; +import { InjectRepository } from "@nestjs/typeorm"; +import { Project } from "src/project/entities/project.entity"; + +@Injectable() +export class MigrationService { + constructor( + @InjectRepository(Migration) + private readonly migrationRepository: Repository + @InjectRepository(Project) + private readonly projectRepository: Repository + ) {} + + create(tables: MigrationTable[], projectId: string): Promise { + const project = this.projectRepository.findOne({ + where: { token: projectId }, + }); + + const migrations = this.migrationRepository.find({ + where: { + + } + }) + } +} diff --git a/src/project/entities/project.entity.ts b/src/project/entities/project.entity.ts index f1c36e9..a62dd00 100644 --- a/src/project/entities/project.entity.ts +++ b/src/project/entities/project.entity.ts @@ -1,3 +1,4 @@ +import { Migration } from "src/migration/entities/migration.entity"; import { Token } from "../../api/entities/token.entity"; import { Query } from "../../query/entities/query.entity"; import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; @@ -13,6 +14,9 @@ export class Project { @OneToMany(() => Token, (token) => token.project) apiTokens: Token[]; + @OneToMany(() => Migration, (migration) => migration.project) + migrations: Migration[]; + @OneToMany(() => Query, (query) => query.project) queries: Query[]; }