mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Merge pull request #1548 from umami-software/feat/um-58-account-uuid
Feat/um 58 account UUID
This commit is contained in:
commit
d6854d4ff9
11
db/mysql/migrations/04_account_uuid/migration.sql
Normal file
11
db/mysql/migrations/04_account_uuid/migration.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `account` ADD COLUMN `account_uuid` VARCHAR(36);
|
||||||
|
|
||||||
|
-- Backfill UUID
|
||||||
|
UPDATE `account` SET account_uuid=(SELECT uuid());
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `account` MODIFY `account_uuid` VARCHAR(36) NOT NULL;
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX `account_account_uuid_key` ON `account`(`account_uuid`);
|
@ -8,13 +8,14 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model account {
|
model account {
|
||||||
user_id Int @id @default(autoincrement()) @db.UnsignedInt
|
user_id Int @id @default(autoincrement()) @db.UnsignedInt
|
||||||
username String @unique() @db.VarChar(255)
|
username String @unique() @db.VarChar(255)
|
||||||
password String @db.VarChar(60)
|
password String @db.VarChar(60)
|
||||||
is_admin Boolean @default(false)
|
is_admin Boolean @default(false)
|
||||||
created_at DateTime? @default(now()) @db.Timestamp(0)
|
created_at DateTime? @default(now()) @db.Timestamp(0)
|
||||||
updated_at DateTime? @default(now()) @db.Timestamp(0)
|
updated_at DateTime? @default(now()) @db.Timestamp(0)
|
||||||
website website[]
|
account_uuid String @unique() @db.VarChar(36)
|
||||||
|
website website[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model event {
|
model event {
|
||||||
|
12
db/postgresql/migrations/04_account_uuid/migration.sql
Normal file
12
db/postgresql/migrations/04_account_uuid/migration.sql
Normal file
@ -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");
|
@ -8,13 +8,14 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model account {
|
model account {
|
||||||
user_id Int @id @default(autoincrement())
|
user_id Int @id @default(autoincrement())
|
||||||
username String @unique @db.VarChar(255)
|
username String @unique @db.VarChar(255)
|
||||||
password String @db.VarChar(60)
|
password String @db.VarChar(60)
|
||||||
is_admin Boolean @default(false)
|
is_admin Boolean @default(false)
|
||||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||||
updated_at DateTime? @default(now()) @db.Timestamptz(6)
|
updated_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||||
website website[]
|
account_uuid String @unique @db.Uuid
|
||||||
|
website website[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model event {
|
model event {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
|
import { ok, unauthorized, methodNotAllowed, badRequest, hashPassword } from 'next-basics';
|
||||||
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'queries';
|
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'queries';
|
||||||
import { useAuth } from 'lib/middleware';
|
import { useAuth } from 'lib/middleware';
|
||||||
|
import { uuid } from 'lib/crypto';
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
@ -47,7 +48,11 @@ export default async (req, res) => {
|
|||||||
return badRequest(res, 'Account already exists');
|
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);
|
return ok(res, created);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const { PrismaClient } = require('@prisma/client');
|
const { PrismaClient } = require('@prisma/client');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
@ -39,7 +40,7 @@ async function checkConnection() {
|
|||||||
|
|
||||||
async function checkTables() {
|
async function checkTables() {
|
||||||
try {
|
try {
|
||||||
await prisma.account.findFirst();
|
await prisma.$queryRaw`select * from account limit 1`;
|
||||||
|
|
||||||
success('Database tables found.');
|
success('Database tables found.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user