From 9a890135bc0e87223b2bf4016268872a120c4f2e Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Thu, 26 Jan 2023 14:13:08 +0100 Subject: [PATCH] Added prisma stuff --- .dockerignore | 7 ++ .gitignore | 4 + package-lock.json | 26 +++++++ package.json | 2 + .../migration.sql | 73 +++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 62 ++++++++++++++++ tsconfig.json | 2 +- 8 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 prisma/migrations/20230126130741_initial_migration/migration.sql create mode 100644 prisma/migrations/migration_lock.toml create mode 100644 prisma/schema.prisma diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8c3e772 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.dockerignore + +node_modules +dist + +.vscode +.idea \ No newline at end of file diff --git a/.gitignore b/.gitignore index a3a293b..87c70db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ +mysql-data + node_modules dist +.env + .vscode .idea \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bf14252..3193bec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@prisma/client": "^4.9.0", "concurrently": "^7.6.0", "express": "^4.18.2", "nodemon": "^2.0.20", @@ -1156,12 +1157,37 @@ "@jridgewell/sourcemap-codec": "1.4.14" } }, + "node_modules/@prisma/client": { + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.9.0.tgz", + "integrity": "sha512-bz6QARw54sWcbyR1lLnF2QHvRW5R/Jxnbbmwh3u+969vUKXtBkXgSgjDA85nji31ZBlf7+FrHDy5x+5ydGyQDg==", + "hasInstallScript": true, + "dependencies": { + "@prisma/engines-version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5" + }, + "engines": { + "node": ">=14.17" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, "node_modules/@prisma/engines": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.9.0.tgz", "integrity": "sha512-t1pt0Gsp+HcgPJrHFc+d/ZSAaKKWar2G/iakrE07yeKPNavDP3iVKPpfXP22OTCHZUWf7OelwKJxQgKAm5hkgw==", "hasInstallScript": true }, + "node_modules/@prisma/engines-version": { + "version": "4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5.tgz", + "integrity": "sha512-M16aibbxi/FhW7z1sJCX8u+0DriyQYY5AyeTH7plQm9MLnURoiyn3CZBqAyIoQ+Z1pS77usCIibYJWSgleBMBA==" + }, "node_modules/@sideway/address": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", diff --git a/package.json b/package.json index e4d40c1..30dbc54 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "", "main": "app.js", + "type": "module", "scripts": { "build": "tsc", "build:dev": "tsc -w", @@ -12,6 +13,7 @@ "author": "", "license": "ISC", "dependencies": { + "@prisma/client": "^4.9.0", "concurrently": "^7.6.0", "express": "^4.18.2", "nodemon": "^2.0.20", diff --git a/prisma/migrations/20230126130741_initial_migration/migration.sql b/prisma/migrations/20230126130741_initial_migration/migration.sql new file mode 100644 index 0000000..140fa1c --- /dev/null +++ b/prisma/migrations/20230126130741_initial_migration/migration.sql @@ -0,0 +1,73 @@ +-- CreateTable +CREATE TABLE `User` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `email` VARCHAR(191) NOT NULL, + `password` VARCHAR(191) NOT NULL, + `name` VARCHAR(191) NOT NULL, + `picture_path` VARCHAR(191) NOT NULL, + `created_at` DATETIME(3) NOT NULL, + `updated_at` DATETIME(3) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Snippet` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(191) NOT NULL, + `code` VARCHAR(191) NOT NULL, + `created_at` DATETIME(3) NOT NULL, + `updated_at` DATETIME(3) NOT NULL, + `user_id` INTEGER NOT NULL, + `category_id` INTEGER NOT NULL, + `language_id` INTEGER NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Category` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Language` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Snippet_tag` ( + `tag_id` INTEGER NOT NULL, + `snippet_id` INTEGER NOT NULL, + + PRIMARY KEY (`tag_id`, `snippet_id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Tag` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(191) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `Snippet` ADD CONSTRAINT `Snippet_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Snippet` ADD CONSTRAINT `Snippet_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `Category`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Snippet` ADD CONSTRAINT `Snippet_language_id_fkey` FOREIGN KEY (`language_id`) REFERENCES `Language`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Snippet_tag` ADD CONSTRAINT `Snippet_tag_tag_id_fkey` FOREIGN KEY (`tag_id`) REFERENCES `Tag`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Snippet_tag` ADD CONSTRAINT `Snippet_tag_snippet_id_fkey` FOREIGN KEY (`snippet_id`) REFERENCES `Snippet`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5a788a --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "mysql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..280fc3b --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,62 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") +} + +model User { + id Int @id @default(autoincrement()) + email String + password String + name String + picture_path String + created_at DateTime + updated_at DateTime + Snippet Snippet[] +} + +model Snippet { + id Int @id @default(autoincrement()) + title String + code String + created_at DateTime + updated_at DateTime + + user_id Int + user User @relation(fields: [user_id], references: [id]) + category_id Int + category Category @relation(fields: [category_id], references: [id]) + language_id Int + language Language @relation(fields: [language_id], references: [id]) + Snippet_tag Snippet_tag[] +} + +model Category { + id Int @id @default(autoincrement()) + name String + Snippet Snippet[] +} + +model Language { + id Int @id @default(autoincrement()) + name String + Snippet Snippet[] +} + +model Snippet_tag { + tag_id Int + tag Tag @relation(fields: [tag_id], references: [id]) + snippet_id Int + snippet Snippet @relation(fields: [snippet_id], references: [id]) + + @@id([tag_id, snippet_id]) +} + +model Tag { + id Int @id @default(autoincrement()) + name String + Snippet_tag Snippet_tag[] +} diff --git a/tsconfig.json b/tsconfig.json index a0a1784..9429a84 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ /* Modules */ "module": "ES2022", /* Specify what module code is generated. */ "rootDir": "./src", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */