Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

add uuid to account

Brian Caoadb0a0600636
diff --git a/db/postgresql/migrations/04_account_uuid/migration.sql b/db/postgresql/migrations/04_account_uuid/migration.sql
new file mode 100644
index 000000000..f95718d44
--- /dev/null
+++ b/db/postgresql/migrations/04_account_uuid/migration.sql
@@ -0,0 +1,12 @@
+
+-- AlterTable
+ALTER TABLE "account" ADD COLUMN "account_uuid" UUID NULL;
+
+-- Backfill UUID
+UPDATE "account" SET account_uuid = gen_random_uuid();
+
+-- AlterTable
+ALTER TABLE "account" ALTER COLUMN "account_uuid" SET NOT NULL;
+
+-- CreateIndex
+CREATE UNIQUE INDEX "account_account_uuid_key" ON "account"("account_uuid");
diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma
index a76a3da42..d1d346dec 100644
--- a/db/postgresql/schema.prisma
+++ b/db/postgresql/schema.prisma
@@ -8,13 +8,14 @@ datasource db {
}
model account {
- user_id Int @id @default(autoincrement())
- username String @unique @db.VarChar(255)
- password String @db.VarChar(60)
- is_admin Boolean @default(false)
- created_at DateTime? @default(now()) @db.Timestamptz(6)
- updated_at DateTime? @default(now()) @db.Timestamptz(6)
- website website[]
+ user_id Int @id @default(autoincrement())
+ username String @unique @db.VarChar(255)
+ password String @db.VarChar(60)
+ is_admin Boolean @default(false)
+ created_at DateTime? @default(now()) @db.Timestamptz(6)
+ updated_at DateTime? @default(now()) @db.Timestamptz(6)
+ account_uuid String @unique @db.Uuid
+ website website[]
}
model event {
diff --git a/pages/api/account/index.js b/pages/api/account/index.js
index fe9cafe12..a3fc6bc17 100644
--- a/pages/api/account/index.js
+++ b/pages/api/account/index.js
@@ -1,6 +1,7 @@
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'queries';
import { useAuth } from 'lib/middleware';
+import { uuid } from 'lib/crypto';
export default async (req, res) => {
await useAuth(req, res);
@@ -47,7 +48,11 @@ export default async (req, res) => {
return badRequest(res, 'Account already exists');
}
- const created = await createAccount({ username, password: hashPassword(password) });
+ const created = await createAccount({
+ username,
+ password: hashPassword(password),
+ account_uuid: uuid(),
+ });
return ok(res, created);
}