Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma migration #198

Open
wants to merge 7 commits into
base: release-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/typescript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ RUN yarn install

COPY . ./

RUN npx prisma generate --schema=models/prisma/schema.prisma

EXPOSE 8080
ENTRYPOINT ["yarn", "dev"]

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions backend/typescript/models/entity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,3 @@ const EntitySchema: Schema = new Schema({
export default model<Entity>("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
16 changes: 0 additions & 16 deletions backend/typescript/models/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- CreateEnum
CREATE TYPE "enum_entities_enum_field" AS ENUM ('A', 'B', 'C', 'D');

-- CreateEnum
CREATE TYPE "enum_users_role" AS ENUM ('User', 'Admin');

-- CreateTable
CREATE TABLE "SequelizeMeta" (
"name" VARCHAR(255) NOT NULL,

CONSTRAINT "SequelizeMeta_pkey" PRIMARY KEY ("name")
);

-- CreateTable
CREATE TABLE "entities" (
"id" SERIAL NOT NULL,
"string_field" VARCHAR(255) NOT NULL,
"int_field" INTEGER NOT NULL,
"enum_field" "enum_entities_enum_field" NOT NULL,
"string_array_field" VARCHAR(255)[],
"bool_field" BOOLEAN NOT NULL,
"file_name" VARCHAR(255) NOT NULL,
"createdAt" TIMESTAMPTZ(6),
"updatedAt" TIMESTAMPTZ(6),

CONSTRAINT "entities_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "simple_entities" (
"id" SERIAL NOT NULL,
"string_field" VARCHAR(255) NOT NULL,
"int_field" INTEGER NOT NULL,
"enum_field" "enum_entities_enum_field" NOT NULL,
"string_array_field" VARCHAR(255)[],
"bool_field" BOOLEAN NOT NULL,
"createdAt" TIMESTAMPTZ(6),
"updatedAt" TIMESTAMPTZ(6),

CONSTRAINT "simple_entities_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"first_name" VARCHAR(255) NOT NULL,
"last_name" VARCHAR(255) NOT NULL,
"auth_id" VARCHAR(255) NOT NULL,
"role" "enum_users_role" NOT NULL,
"createdAt" TIMESTAMPTZ(6),
"updatedAt" TIMESTAMPTZ(6),

CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "users_auth_id_key" ON "users"("auth_id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
64 changes: 64 additions & 0 deletions backend/typescript/models/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
output = "../../node_modules/.prisma/client"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model SequelizeMeta {
name String @id @db.VarChar(255)
}

model entities {
id Int @id @default(autoincrement())
string_field String @db.VarChar(255)
int_field Int
enum_field enum_entities_enum_field
string_array_field String[] @db.VarChar(255)
bool_field Boolean
file_name String @db.VarChar(255)
createdAt DateTime? @db.Timestamptz(6)
updatedAt DateTime? @db.Timestamptz(6)
}

model simple_entities {
id Int @id @default(autoincrement())
string_field String @db.VarChar(255)
int_field Int
enum_field enum_entities_enum_field
string_array_field String[] @db.VarChar(255)
bool_field Boolean
createdAt DateTime? @db.Timestamptz(6)
updatedAt DateTime? @db.Timestamptz(6)
}

model users {
id Int @id @default(autoincrement())
first_name String @db.VarChar(255)
last_name String @db.VarChar(255)
auth_id String @unique @db.VarChar(255)
role enum_users_role
createdAt DateTime? @db.Timestamptz(6)
updatedAt DateTime? @db.Timestamptz(6)
}

enum enum_entities_enum_field {
A
B
C
D
}

enum enum_users_role {
User
Admin
}
26 changes: 1 addition & 25 deletions backend/typescript/models/simpleEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,4 @@ const SimpleEntitySchema: Schema = new Schema({

export default model<SimpleEntity>("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
// } mongodb
22 changes: 1 addition & 21 deletions backend/typescript/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,4 @@ const UserSchema: Schema = new Schema({

export default mongoose.model<User>("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
// } mongodb
4 changes: 2 additions & 2 deletions backend/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "5.14.0",
"@types/graphql-upload": "^8.0.6",
"@types/json2csv": "^5.0.3",
"@types/multer": "^1.4.6",
Expand All @@ -37,9 +38,8 @@
"node-fetch": "^2.6.1",
"nodemailer": "^6.5.0",
"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",
Expand Down
Loading