From c8a29885564f68aa0193ccba54705a3c9d3de2c3 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Tue, 19 Apr 2022 12:23:27 +0100 Subject: [PATCH] added prisma and schema --- .env.local | 91 +++++++++++++ lib/entities.js | 125 ------------------ package.json | 5 +- .../migration.sql | 57 ++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 26 ++-- 6 files changed, 170 insertions(+), 137 deletions(-) create mode 100644 .env.local delete mode 100644 lib/entities.js create mode 100644 prisma/migrations/20220419063544_nextauthmigration/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/.env.local b/.env.local new file mode 100644 index 00000000..152881e8 --- /dev/null +++ b/.env.local @@ -0,0 +1,91 @@ + + +ACCESS_TOKEN_ENDPOINT = https://login.microsoftonline.com/ +//ESNR Tenant +TENANT = a8d860de-d5e1-45af-8376-d93f02e6b502 +//WGO Tenant +//TENANT = 9ac1a5ab-cd58-409e-a1b6-6b10422a68f5 +GRANT_TYPE = "client_credentials" + +HASHKEY = 028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c +NEXT_PUBLIC_HASHKEY = 028ffbae928d7191c0017f298260995f901d78eabde1436c0af0423459cc3715832136d84f68818d3a96399467b52143e273d4f3bf4ae190848891535421cd6c + + +//Dev oauth ESNR +CLIENT_ID = e082def0-3453-461f-9a5e-f4ab127dc015 +CLIENT_SECRET = qW.7Q~TSr3sZmLEnJQJPXEdOckb_yo2t1yJmY +RELAY_ROOT = https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/ +RELAYURI = "dev-pedw-ns.servicebus.windows.net" +RELAYPATH = "dev-pedw-hc" + + +//Test Oauth ESNR +//CLIENT_ID = 6619ad85-c908-490d-811b-de8c93c0f2aa +//CLIENT_SECRET = qKo7Q~5QvLEplbwnBbint_I5lXqx_-kDm8Vj- +//RELAY_ROOT = https://test-pedw-ns.servicebus.windows.net/test-pedw-hc/ +//RELAYURI = "test-pedw-ns.servicebus.windows.net" +//RELAYPATH = "test-pedw-hc" + + +//Preprod Oauth WGO +//CLIENT_ID = ab6c4678-b31a-4eb3-b429-e039120e488a +//CLIENT_SECRET = Ioo7Q~RJfhWsE45wPsuHm1CzRk1SppnNN3lZF +//RELAY_ROOT = https://pp-pedw-ns.servicebus.windows.net/pp-pedw-hc/ +//RELAYURI = "pp-pedw-ns.servicebus.windows.net" +//RELAYPATH = "pp-pedw-hc" + + + +//Prod Oauth WGO +//CLIENT_ID = 3e4141a3-1fbd-454e-98f0-7f3a4f14a3cc +//CLIENT_SECRET = mJN7Q~lFu.xFGa5KCc.zwIm_fJAWxajyQaFo~ +//RELAY_ROOT = https://prod-pedw-ns.servicebus.windows.net/prod-pedw-hc/ +//RELAYURI = "prod-pedw-ns.servicebus.windows.net" +//RELAYPATH = "prod-pedw-hc" + + +GOOGLE_TAG_MANAGER = GTM-T78CBC3 +SHOWLOGIN = "true" +SHOWREPRESENTATIONS = false +SHOWFILEUPLOAD = "false" +SHOWMAPS = "true" +//BASIC_AUTH_CREDENTIALS = pinswg:password|pinswg2:password2 + + +PORT= "3000" +DEFAULT_DOMAIN = "localhost" +I18N_DOMAIN = "cymru.local" +//I18N_DOMAIN ="dev-gwaithcynllunio.gwasanaeth.llyw.cymru" +//I18N_DOMAIN ="stage-gwaithcynllunio.gwasanaeth.llyw.cymru" +//I18N_DOMAIN ="pp-gwaithcynllunio.gwasanaeth.llyw.cymru"s +//I18N_DOMAIN ="gwaithcynllunio.gwasanaeth.llyw.cymru" + + +//gov gateway +GG_PROVIDER_CONFIG_ENDPOINT = "https://api.ete.access.service.gov.uk/.well-known/openid-configuration" +GG_CLIENT_ID = 5vTukeSpN7d6uBV7YLb7A5wOctzzkZ +GG_CLIENT_SECRET = z1PGLAKPxIhjMBegTdzX22AayIORc1GsCbMQZ6mieBn7zChjzzxup5lkIByEmsYS +//GG_REDIRECT_URI = "http://localhost:3000" +GG_REDIRECT_URI = "https://dev-planningcasework.service.gov.wales" + +NEXT_PUBLIC_GG_CLIENT_ID = 5vTukeSpN7d6uBV7YLb7A5wOctzzkZ +NEXT_PUBLIC_GG_REDIRECT_URI = "http://localhost:3000" + +API_ROOT = "http://localhost:3000" + + +GOOGLE_MAP_API_KEY = AIzaSyCzeVrHt544bp_72YCFkw21eDsmI2JEsQo + + + +//Next Auth vars +EMAIL_SERVER_HOST=smtp.sendgrid.net +EMAIL_SERVER_PORT=465 +EMAIL_SERVER_USER=apikey +EMAIL_SERVER_PASSWORD=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 +EMAIL_FROM=rob@rdbsolutions.co.uk + +NEXTAUTH_URL=http://localhost:3000 +DATABASE_URL=mysql://nextAuthAdmin:!Sky9fish1972@77.68.17.157:3306/nextauthDB?synchronise=true + +SECRET=SuperSecret diff --git a/lib/entities.js b/lib/entities.js deleted file mode 100644 index f6cfc67b..00000000 --- a/lib/entities.js +++ /dev/null @@ -1,125 +0,0 @@ -import { - Entity, - PrimaryGeneratedColumn, - Column, - ManyToOne, - OneToMany, - ValueTransformer, -} from "typeorm" - -const transformer = { - date: { - from: (date ) => date && new Date(parseInt(date, 10)), - to: (date) => date?.valueOf().toString(), - }, - bigint: { - from: (bigInt) => bigInt && parseInt(bigInt, 10), - to: (bigInt) => bigInt?.toString(), - }, -} - -@Entity({ name: "users" }) -export class UserEntity { - @PrimaryGeneratedColumn("uuid") - id = undefined; - - @Column("varchar") - name! - - - @Column({ type: "varchar", nullable: true, unique: true }) - email!: string | null - - @Column({ type: "varchar", nullable: true, transformer: transformer.date }) - emailVerified!: string | null - - @Column("varchar") - image!: string | null - - @OneToMany(() => SessionEntity, (session) => session.userId) - sessions!: SessionEntity[] - - @OneToMany(() => AccountEntity, (account) => account.userId) - accounts!: AccountEntity[] -} - -@Entity({ name: "accounts" }) -export class AccountEntity { - @PrimaryGeneratedColumn("uuid") - id!: string - - @Column({ type: "uuid" }) - userId!: string - - @Column() - type!: string - - @Column() - provider!: string - - @Column() - providerAccountId!: string - - @Column("varchar") - refresh_token!: string | null - - @Column("varchar") - access_token!: string | null - - @Column({ - nullable: true, - type: "bigint", - transformer: transformer.bigint, - }) - expires_at!: number | null - - @Column("varchar") - token_type!: string | null - - @Column("varchar") - scope!: string | null - - @Column("varchar") - id_token!: string | null - - @Column("varchar") - session_state!: string | null - - @ManyToOne(() => UserEntity, (user) => user.accounts, { - createForeignKeyConstraints: true, - }) - user!: UserEntity -} - -@Entity({ name: "sessions" }) -export class SessionEntity { - @PrimaryGeneratedColumn("uuid") - id!: string - - @Column({ unique: true }) - sessionToken!: string - - @Column({ type: "uuid" }) - userId!: string - - @Column({ transformer: transformer.date }) - expires!: string - - @ManyToOne(() => UserEntity, (user) => user.sessions) - user!: UserEntity -} - -@Entity({ name: "verification_tokens" }) -export class VerificationTokenEntity { - @PrimaryGeneratedColumn("uuid") - id!: string - - @Column() - token!: string - - @Column() - identifier!: string - - @Column({ transformer: transformer.date }) - expires!: string -} \ No newline at end of file diff --git a/package.json b/package.json index 24411f37..4dd89e94 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,7 @@ "@googlemaps/react-wrapper": "^1.1.24", "@magic-sdk/admin": "^1.4.0", "@next-auth/prisma-adapter": "^1.0.3", - "@next-auth/typeorm-legacy-adapter": "^1.0.3", - "@prisma/client": "3.3.0", + "@prisma/client": "^3.12.0", "@webdeb/next-styles": "^1.1.1", "applicationinsights": "^2.2.0", "axios": "^0.24.0", @@ -80,6 +79,6 @@ "eslint": "^8.6.0", "eslint-config-next": "^12.0.8", "prettier": "2.5.1", - "prisma": "3.3.0" + "prisma": "^3.12.0" } } diff --git a/prisma/migrations/20220419063544_nextauthmigration/migration.sql b/prisma/migrations/20220419063544_nextauthmigration/migration.sql new file mode 100644 index 00000000..b59e5472 --- /dev/null +++ b/prisma/migrations/20220419063544_nextauthmigration/migration.sql @@ -0,0 +1,57 @@ +-- CreateTable +CREATE TABLE `accounts` ( + `id` VARCHAR(191) NOT NULL, + `user_id` VARCHAR(191) NOT NULL, + `type` VARCHAR(191) NOT NULL, + `provider` VARCHAR(191) NOT NULL, + `provider_account_id` VARCHAR(191) NOT NULL, + `refresh_token` TEXT NULL, + `access_token` TEXT NULL, + `expires_at` INTEGER NULL, + `token_type` VARCHAR(191) NULL, + `scope` VARCHAR(191) NULL, + `id_token` TEXT NULL, + `session_state` VARCHAR(191) NULL, + + UNIQUE INDEX `accounts_provider_provider_account_id_key`(`provider`, `provider_account_id`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `sessions` ( + `id` VARCHAR(191) NOT NULL, + `session_token` VARCHAR(191) NOT NULL, + `user_id` VARCHAR(191) NOT NULL, + `expires` DATETIME(3) NOT NULL, + + UNIQUE INDEX `sessions_session_token_key`(`session_token`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `users` ( + `id` VARCHAR(191) NOT NULL, + `name` VARCHAR(191) NULL, + `email` VARCHAR(191) NULL, + `email_verified` DATETIME(3) NULL, + `image` VARCHAR(191) NULL, + + UNIQUE INDEX `users_email_key`(`email`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `verificationtokens` ( + `identifier` VARCHAR(191) NOT NULL, + `token` VARCHAR(191) NOT NULL, + `expires` DATETIME(3) NOT NULL, + + UNIQUE INDEX `verificationtokens_token_key`(`token`), + UNIQUE INDEX `verificationtokens_identifier_token_key`(`identifier`, `token`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `accounts` ADD CONSTRAINT `accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `sessions` ADD CONSTRAINT `sessions_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..e5a788a7 --- /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 index dc22b71b..e260260d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,41 +7,48 @@ generator client { provider = "prisma-client-js" } + + model Account { id String @id @default(cuid()) - userId String + userId String @map("user_id") type String provider String - providerAccountId String - refresh_token String? @db.Text - access_token String? @db.Text + providerAccountId String @map("provider_account_id") + refresh_token String? @db.Text + access_token String? @db.Text expires_at Int? token_type String? scope String? - id_token String? @db.Text + id_token String? @db.Text session_state String? user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([provider, providerAccountId]) + @@map("accounts") } model Session { id String @id @default(cuid()) - sessionToken String @unique - userId String + sessionToken String @unique @map("session_token") + userId String @map("user_id") expires DateTime user User @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@map("sessions") } model User { id String @id @default(cuid()) name String? email String? @unique - emailVerified DateTime? + emailVerified DateTime? @map("email_verified") image String? accounts Account[] sessions Session[] + + @@map("users") } model VerificationToken { @@ -50,4 +57,5 @@ model VerificationToken { expires DateTime @@unique([identifier, token]) -} \ No newline at end of file + @@map("verificationtokens") +}