Skip to content

Commit

Permalink
migrate to drizzle, GL reviewing this shit
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed May 19, 2024
1 parent 793e8fb commit 9da2b31
Show file tree
Hide file tree
Showing 79 changed files with 3,941 additions and 3,050 deletions.
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ PORT=3000

# Database settings

# Choose mysql or postgres
DB_DIALECT=<mysql|postgres>
DB_HOST=localhost
#DB_PORT=<3306|5432>
DB_PORT=5432
DB_USER=ilmo_user
DB_PASSWORD=password
DB_DATABASE=ilmomasiina
Expand Down
104 changes: 49 additions & 55 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
module.exports = {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
parser: "@typescript-eslint/parser",
parserOptions: {
project: [
"packages/ilmomasiina-models/tsconfig.json",
"packages/ilmomasiina-components/tsconfig.json",
"packages/ilmomasiina-frontend/tsconfig.json",
"packages/ilmomasiina-backend/tsconfig.json"
"packages/ilmomasiina-backend/tsconfig.json",
],
"tsconfigRootDir": __dirname,
tsconfigRootDir: __dirname,
// https://github.com/typescript-eslint/typescript-eslint/issues/2094
"EXPERIMENTAL_useSourceOfProjectReferenceRedirect": true
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
},
"ignorePatterns": [
ignorePatterns: [
"**/node_modules/**",
"**/dist/**",
"**/build/**",
".eslintrc.js",
"jest.config.js",
"*.scss",
"*.json"
"*.json",
],
"settings": {
"react": {
"pragma": "React",
"version": "16.12"
settings: {
react: {
pragma: "React",
version: "16.12",
},
},
"extends": [
"airbnb",
"airbnb/hooks",
"airbnb-typescript"
],
"plugins": [
"@typescript-eslint",
"promise",
"simple-import-sort",
"jest"
],
"env": {
"browser": true
extends: ["airbnb", "airbnb/hooks", "airbnb-typescript"],
plugins: ["@typescript-eslint", "promise", "simple-import-sort", "jest"],
env: {
browser: true,
},
"rules": {
"max-len": ["error", 120, 2],
rules: {
"max-len": "off",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/quotes": ["error", "single"],
// To allow grouping of class members - especially for Models.
Expand All @@ -51,7 +42,7 @@ module.exports = {
// Allow i++ in for loops.
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
// We are targeting ES5 or higher.
"radix": ["error", "as-needed"],
radix: ["error", "as-needed"],
// ...I know what I'm doing.
"no-control-regex": "off",
// Not usable with formik.
Expand All @@ -61,53 +52,56 @@ module.exports = {
// Definitely a valid performance concern, but implementing this correctly is
// a giant PITA - the default config ignores arrow functions but they don't solve
// the problem at all, and useCallback is just plain ugly.
"react/jsx-no-bind": "off",
"react/jsx-no-bind": "off", // Note: you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": "off",
// Add any custom hooks here
"react-hooks/exhaustive-deps": ["error", {
additionalHooks: "useAbortableEffect|useAbortablePromise",
}],
"react-hooks/exhaustive-deps": [
"error",
{
additionalHooks: "useAbortableEffect|useAbortablePromise",
},
],
// Prefer arrow functions to functions expressions, as that's what was done
// when this rule was introduced.
"react/function-component-definition": ["error", {
namedComponents: ["function-declaration", "arrow-function"],
unnamedComponents: "arrow-function",
}],
// Allow dev deps in test files.
"import/no-extraneous-dependencies": ["error", {
devDependencies: [
"**/test/**",
"**/vite.config.ts",
"**/vitest.config.ts",
"**/.eslintrc.js",
"**/rollupMomentPlugin.ts"
],
}],
"react/function-component-definition": [
"error",
{
namedComponents: ["function-declaration", "arrow-function"],
unnamedComponents: "arrow-function",
},
],
// Sort imports: React first, then npm packages, then local files, then CSS.
"simple-import-sort/imports": [
"error",
{
"groups": [
groups: [
["^react$"],
["^@?\\w"],
// Anything that does not start with a dot.
["^[^.]"],
// Anything that starts with a dot, or is from one of our packages.
["^@tietokilta/", "^"],
// Css
["css$"]
]
}
["css$"],
],
},
],
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": "off",
// Prevent imports from "src/...". VS Code adds these automatically, but they
// break when compiled.
"no-restricted-imports": [
"error",
{
"patterns": [{
group: ["src/*"],
message: "This import will break when compiled by tsc. Use a relative path instead, or \"../src/\" in test files."
}],
patterns: [
{
group: ["src/*"],
message:
'This import will break when compiled by tsc. Use a relative path instead, or "../src/" in test files.',
},
],
},
],
}
},
};
22 changes: 22 additions & 0 deletions packages/ilmomasiina-backend/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Config } from 'drizzle-kit';

import envConfig from './src/config';

const config: Config = {
dialect: 'postgresql',
out: './drizzle',
schema: './src/drizzle/schema.ts',
dbCredentials: {
host: envConfig.dbHost,
port: envConfig.dbPort ?? 5432,
user: envConfig.dbUser,
password: envConfig.dbPassword,
database: envConfig.dbDatabase,
ssl: envConfig.dbSsl,
},
// Print all statements
verbose: envConfig.debugDbLogging,
// Always ask for confirmation
strict: true,
};
export default config;
153 changes: 153 additions & 0 deletions packages/ilmomasiina-backend/drizzle/0000_open_adam_destine.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
-- Current sql file was generated after introspecting the database
-- If you want to run this migration please uncomment this code before executing migrations

DO $$ BEGIN
CREATE TYPE "public"."enum_question_type" AS ENUM('text', 'textarea', 'number', 'select', 'checkbox');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."enum_signup_status" AS ENUM('in-quota', 'in-open', 'in-queue');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "SequelizeMeta" (
"name" varchar(255) PRIMARY KEY NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "auditlog" (
"id" serial PRIMARY KEY NOT NULL,
"user" varchar(255),
"ipAddress" varchar(64) NOT NULL,
"action" varchar(32) NOT NULL,
"eventId" char(12),
"eventName" varchar(255),
"signupId" char(12),
"signupName" varchar(255),
"extra" text,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "quota" (
"id" char(12) PRIMARY KEY NOT NULL,
"eventId" char(12) NOT NULL,
"order" integer NOT NULL,
"title" varchar(255) NOT NULL,
"size" integer,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "event" (
"id" char(12) PRIMARY KEY NOT NULL,
"title" varchar(255) NOT NULL,
"slug" varchar(255) NOT NULL,
"date" timestamp with time zone,
"registrationStartDate" timestamp with time zone,
"registrationEndDate" timestamp with time zone,
"openQuotaSize" integer DEFAULT 0,
"description" text,
"price" varchar(255),
"location" varchar(255),
"facebookUrl" varchar(255),
"webpageUrl" varchar(255),
"category" varchar(255) DEFAULT ''::character varying NOT NULL,
"draft" boolean DEFAULT true NOT NULL,
"listed" boolean DEFAULT true NOT NULL,
"signupsPublic" boolean DEFAULT false NOT NULL,
"nameQuestion" boolean DEFAULT true NOT NULL,
"emailQuestion" boolean DEFAULT true NOT NULL,
"verificationEmail" text,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
"endDate" timestamp with time zone,
CONSTRAINT "event_slug_key" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "question" (
"id" char(12) PRIMARY KEY NOT NULL,
"eventId" char(12) NOT NULL,
"order" integer NOT NULL,
"question" varchar(255) NOT NULL,
"type" "enum_question_type" NOT NULL,
"options" varchar(255),
"required" boolean DEFAULT true NOT NULL,
"public" boolean DEFAULT false NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "answer" (
"id" serial PRIMARY KEY NOT NULL,
"questionId" char(12) NOT NULL,
"signupId" char(12) NOT NULL,
"answer" varchar(255) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user" (
"id" serial PRIMARY KEY NOT NULL,
"email" varchar(255) NOT NULL,
"password" varchar(255) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
CONSTRAINT "user_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "signup" (
"id" char(12) PRIMARY KEY NOT NULL,
"quotaId" char(12) NOT NULL,
"firstName" varchar(255),
"lastName" varchar(255),
"namePublic" boolean DEFAULT false,
"email" varchar(255),
"confirmedAt" timestamp with time zone,
"status" "enum_signup_status",
"position" integer,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
"language" varchar(8)
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "quota" ADD CONSTRAINT "quota_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "public"."event"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "question" ADD CONSTRAINT "question_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "public"."event"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "answer" ADD CONSTRAINT "answer_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "public"."question"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "answer" ADD CONSTRAINT "answer_signupId_fkey" FOREIGN KEY ("signupId") REFERENCES "public"."signup"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "signup" ADD CONSTRAINT "signup_quotaId_fkey" FOREIGN KEY ("quotaId") REFERENCES "public"."quota"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_quota_main" ON "quota" ("eventId","deletedAt");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_answer_main" ON "answer" ("questionId","signupId","deletedAt");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_signup_main" ON "signup" ("quotaId","confirmedAt","createdAt","deletedAt");
Loading

0 comments on commit 9da2b31

Please sign in to comment.