diff --git a/backend/typescript/migrations/2022.01.10T17.43.07.create-entity-table.ts b/backend/typescript/migrations/2022.01.10T17.43.07.create-entity-table.ts deleted file mode 100644 index 7f4d37f..0000000 --- a/backend/typescript/migrations/2022.01.10T17.43.07.create-entity-table.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { DataType } from "sequelize-typescript"; - -import { Migration } from "../umzug"; - -const TABLE_NAME = "entities"; - -export const up: Migration = async ({ context: sequelize }) => { - await sequelize.getQueryInterface().createTable(TABLE_NAME, { - id: { - type: DataType.INTEGER, - allowNull: false, - primaryKey: true, - autoIncrement: true, - }, - string_field: { - type: DataType.STRING, - allowNull: false, - }, - int_field: { - type: DataType.INTEGER, - allowNull: false, - }, - enum_field: { - type: DataType.ENUM("A", "B", "C", "D"), - allowNull: false, - }, - string_array_field: { - type: DataType.ARRAY(DataType.STRING), - allowNull: false, - }, - bool_field: { - type: DataType.BOOLEAN, - allowNull: false, - }, - file_name: { - type: DataType.STRING, - allowNull: false, - }, - createdAt: DataType.DATE, - updatedAt: DataType.DATE, - }); -}; - -export const down: Migration = async ({ context: sequelize }) => { - await sequelize.getQueryInterface().dropTable(TABLE_NAME); -}; diff --git a/backend/typescript/migrations/2022.01.10T17.43.41.create-user-table.ts b/backend/typescript/migrations/2022.01.10T17.43.41.create-user-table.ts deleted file mode 100644 index 4e7e8d0..0000000 --- a/backend/typescript/migrations/2022.01.10T17.43.41.create-user-table.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { DataType } from "sequelize-typescript"; - -import { Migration } from "../umzug"; - -const TABLE_NAME = "users"; - -export const up: Migration = async ({ context: sequelize }) => { - await sequelize.getQueryInterface().createTable(TABLE_NAME, { - id: { - type: DataType.INTEGER, - allowNull: false, - primaryKey: true, - autoIncrement: true, - }, - first_name: { - type: DataType.STRING, - allowNull: false, - }, - last_name: { - type: DataType.STRING, - allowNull: false, - }, - auth_id: { - type: DataType.STRING, - allowNull: false, - }, - role: { - type: DataType.ENUM("User", "Admin"), - allowNull: false, - }, - createdAt: DataType.DATE, - updatedAt: DataType.DATE, - }); -}; - -export const down: Migration = async ({ context: sequelize }) => { - await sequelize.getQueryInterface().dropTable(TABLE_NAME); -}; diff --git a/backend/typescript/models/entity.model.ts b/backend/typescript/models/entity.model.ts index 3983e6c..7d13955 100644 --- a/backend/typescript/models/entity.model.ts +++ b/backend/typescript/models/entity.model.ts @@ -41,30 +41,3 @@ const EntitySchema: Schema = new Schema({ export default model("Entity", EntitySchema); // } mongodb -// postgresql { -import { Column, Model, Table, DataType } from "sequelize-typescript"; - -import { Letters } from "../types"; - -@Table({ tableName: "entities" }) -export default class Entity extends Model { - @Column - string_field!: string; - - @Column - int_field!: number; - - @Column({ type: DataType.ENUM("A", "B", "C", "D") }) - enum_field!: Letters; - - @Column({ type: DataType.ARRAY(DataType.STRING) }) - string_array_field!: string[]; - - @Column - bool_field!: boolean; - - @Column - file_name!: string; -} - -// } postgresql diff --git a/backend/typescript/models/index.ts b/backend/typescript/models/index.ts index 8420568..3fcabcf 100644 --- a/backend/typescript/models/index.ts +++ b/backend/typescript/models/index.ts @@ -1,19 +1,3 @@ -// postgresql { -import * as path from "path"; -import { Sequelize } from "sequelize-typescript"; - -const DATABASE_URL = - process.env.NODE_ENV === "production" - ? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ - process.env.DATABASE_URL! - : `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.DB_HOST}:5432/${process.env.POSTGRES_DB_DEV}`; - -/* eslint-disable-next-line import/prefer-default-export */ -export const sequelize = new Sequelize(DATABASE_URL, { - models: [path.join(__dirname, "/*.model.ts")], -}); - -// } postgresql // mongodb { import mongoose from "mongoose"; diff --git a/backend/typescript/models/simpleEntity.model.ts b/backend/typescript/models/simpleEntity.model.ts index 0b45d2e..abde5b5 100644 --- a/backend/typescript/models/simpleEntity.model.ts +++ b/backend/typescript/models/simpleEntity.model.ts @@ -36,28 +36,4 @@ const SimpleEntitySchema: Schema = new Schema({ export default model("SimpleEntity", SimpleEntitySchema); -// } mongodb -// postgresql { -import { Column, Model, Table, DataType } from "sequelize-typescript"; - -import { Letters } from "../types"; - -@Table({ tableName: "simple_entities" }) -export default class SimpleEntity extends Model { - @Column - string_field!: string; - - @Column - int_field!: number; - - @Column({ type: DataType.ENUM("A", "B", "C", "D") }) - enum_field!: Letters; - - @Column({ type: DataType.ARRAY(DataType.STRING) }) - string_array_field!: string[]; - - @Column - bool_field!: boolean; -} - -// } postgresql \ No newline at end of file +// } mongodb \ No newline at end of file diff --git a/backend/typescript/models/user.model.ts b/backend/typescript/models/user.model.ts index a7f2873..3225d3a 100644 --- a/backend/typescript/models/user.model.ts +++ b/backend/typescript/models/user.model.ts @@ -33,24 +33,4 @@ const UserSchema: Schema = new Schema({ export default mongoose.model("User", UserSchema); -// } mongodb -// postgresql { -import { Column, DataType, Model, Table } from "sequelize-typescript"; -import { Role } from "../types"; - -@Table({ tableName: "users" }) -export default class User extends Model { - @Column({ type: DataType.STRING }) - first_name!: string; - - @Column({ type: DataType.STRING }) - last_name!: string; - - @Column({ type: DataType.STRING }) - auth_id!: string; - - @Column({ type: DataType.ENUM("User", "Admin") }) - role!: Role; -} - -// } postgresql \ No newline at end of file +// } mongodb \ No newline at end of file diff --git a/backend/typescript/package.json b/backend/typescript/package.json index dd275a2..6f40d79 100644 --- a/backend/typescript/package.json +++ b/backend/typescript/package.json @@ -40,8 +40,6 @@ "pg": "^8.5.1", "prisma": "5.14.0", "reflect-metadata": "^0.1.13", - "sequelize": "^6.5.0", - "sequelize-typescript": "^2.1.0", "swagger-ui-express": "^4.1.6", "ts-node": "^10.0.0", "umzug": "^3.0.0-beta.16", diff --git a/backend/typescript/services/implementations/__tests__/userService.test.ts b/backend/typescript/services/implementations/__tests__/userService.test.ts index f8beec9..dd410d8 100644 --- a/backend/typescript/services/implementations/__tests__/userService.test.ts +++ b/backend/typescript/services/implementations/__tests__/userService.test.ts @@ -1,5 +1,7 @@ // postgresql { import { snakeCase } from "lodash"; +import { PrismaClient } from "@prisma/client"; +const prisma = new PrismaClient(); // } postgresql import UserModel from "../../../models/user.model"; @@ -10,9 +12,6 @@ import { UserDTO } from "../../../types"; // mongodb { import db from "../../../testUtils/testDb"; // } mongodb -// postgresql { -import { testSql } from "../../../testUtils/testDb"; -// } postgresql const testUsers = [ { @@ -70,18 +69,18 @@ describe("mongo userService", (): void => { }); // } mongodb -// postgresql { +// postgresql { describe("pg userService", () => { let userService: UserService; beforeEach(async () => { - await testSql.sync({ force: true }); + await prisma.$connect(); + await prisma.user.deleteMany(); // Clear the User table before each test userService = new UserService(); }); afterAll(async () => { - await testSql.sync({ force: true }); - await testSql.close(); + await prisma.$disconnect(); }); it("getUsers", async () => { @@ -93,7 +92,7 @@ describe("pg userService", () => { return userSnakeCase; }); - await UserModel.bulkCreate(users); + await prisma.user.createMany({ data: users }); const res = await userService.getUsers(); diff --git a/backend/typescript/testUtils/testDb.ts b/backend/typescript/testUtils/testDb.ts index 247cb80..4453409 100644 --- a/backend/typescript/testUtils/testDb.ts +++ b/backend/typescript/testUtils/testDb.ts @@ -1,18 +1,12 @@ // mongodb { import mongoose from "mongoose"; // } mongodb -// postgresql { -import { resolve } from "path"; -// } postgresql + // mongodb { // eslint-disable-next-line import/no-extraneous-dependencies import { MongoMemoryServer } from "mongodb-memory-server"; // } mongodb -// postgresql { -import { Sequelize } from "sequelize-typescript"; -// } postgresql - // mongodb { const mongo = new MongoMemoryServer(); @@ -44,17 +38,3 @@ const mongoTest = { export default mongoTest; // } mongodb - -// postgresql { -const DATABASE_URL = - process.env.NODE_ENV === "production" - ? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ - process.env.DATABASE_URL! - : `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.DB_HOST}:5432/${process.env.POSTGRES_DB_TEST}`; - -/* eslint-disable-next-line import/prefer-default-export */ -export const testSql = new Sequelize(DATABASE_URL, { - models: [resolve(__dirname, "../models/*.model.ts")], - logging: false, -}); -// } postgresql diff --git a/backend/typescript/umzug.ts b/backend/typescript/umzug.ts deleted file mode 100644 index 077322d..0000000 --- a/backend/typescript/umzug.ts +++ /dev/null @@ -1,27 +0,0 @@ -import * as path from "path"; - -import { Umzug, SequelizeStorage } from "umzug"; -import { Sequelize } from "sequelize-typescript"; - -const DATABASE_URL = - process.env.NODE_ENV === "production" - ? /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ - process.env.DATABASE_URL! - : `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.DB_HOST}:5432/${process.env.POSTGRES_DB_DEV}`; - -const sequelize = new Sequelize(DATABASE_URL, { - models: [path.join(__dirname, "/*.model.ts")], -}); - -export const migrator = new Umzug({ - migrations: { - glob: ["migrations/*.ts", { cwd: __dirname }], - }, - context: sequelize, - storage: new SequelizeStorage({ - sequelize, - }), - logger: console, -}); - -export type Migration = typeof migrator._types.migration;