generated from azures04/Base-REST-API
Add MariaDB integration and repositories
Introduce DB support and repos: add modules/database.js (connection pool + runDDL) and SQL DDL files (data/ddl/*) for servers, users, providers, identities and credentials. Add repository layers: users, servers, providers, identities, credentials. Update server.js to run DDL at startup. Update .env.example with DB settings and bump dependencies in package.json/package-lock.json (add mariadb, bump dotenv/helmet/path-to-regexp/zod and dev tool upgrades). Error handling and logging included for DDL and repo operations.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS `servers` (
|
||||
`id` UUID PRIMARY KEY DEFAULT (UUID()),
|
||||
`serverUrl` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`publicKey` TEXT NOT NULL,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` UUID PRIMARY KEY DEFAULT UUID(),
|
||||
`serverId` UUID NULL,
|
||||
`remoteId` VARCHAR(255) NULL,
|
||||
`displayName` VARCHAR(255) NOT NULL,
|
||||
`avatarUrl` TEXT NULL,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT `fk_users_serverId` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `uq_users_server_remote` UNIQUE (`serverId`, `remoteId`)
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS `providers` (
|
||||
`id` UUID PRIMARY KEY DEFAULT UUID(),
|
||||
`name` VARCHAR(64) NOT NULL UNIQUE,
|
||||
`issuerUrl` TEXT NOT NULL,
|
||||
`issuerLogo` TEXT,
|
||||
`isEnabled` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `identities` (
|
||||
`id` UUID PRIMARY KEY DEFAULT UUID(),
|
||||
`userId` UUID NOT NULL,
|
||||
`providerId` UUID NOT NULL,
|
||||
`providerUserId` VARCHAR(255) NOT NULL,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT `fk_identities_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_identities_providerId` FOREIGN KEY (`providerId`) REFERENCES `providers` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `uq_identities_provider_subject` UNIQUE (`providerId`, `providerUserId`)
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS `credentials` (
|
||||
`userId` UUID PRIMARY KEY,
|
||||
`passwordHash` TEXT NOT NULL,
|
||||
`updatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT `fk_credentials_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
)
|
||||
Reference in New Issue
Block a user