Merge branch 'dev' into feat/oidc

This commit is contained in:
Théo LAGACHE
2026-02-24 16:49:16 +01:00
35 changed files with 1191 additions and 3598 deletions
+1
View File
@@ -0,0 +1 @@
ALTER TYPE "public"."dbms_status" ADD VALUE 'sqlite';
@@ -1,13 +0,0 @@
CREATE TABLE "sso_provider" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"issuer" text NOT NULL,
"oidc_config" json,
"saml_config" json,
"user_id" uuid,
"provider_id" text NOT NULL,
"organization_id" text,
"domain" text NOT NULL,
CONSTRAINT "sso_provider_provider_id_unique" UNIQUE("provider_id")
);
--> statement-breakpoint
ALTER TABLE "sso_provider" ADD CONSTRAINT "sso_provider_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
@@ -1,11 +1,25 @@
CREATE TABLE "sso_provider" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"issuer" text NOT NULL,
"oidc_config" json,
"saml_config" json,
"user_id" uuid,
"provider_id" text NOT NULL,
"organization_id" text,
"domain" text NOT NULL,
CONSTRAINT "sso_provider_provider_id_unique" UNIQUE("provider_id")
);
--> statement-breakpoint
ALTER TABLE "passkey" DROP CONSTRAINT "passkey_userId_user_id_fk";
--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "public_key" text NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "user_id" uuid NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "credential_i_d" text NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "credential_id" text NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "device_type" text NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "backed_up" boolean NOT NULL;--> statement-breakpoint
ALTER TABLE "passkey" ADD COLUMN "aaguid" text;--> statement-breakpoint
ALTER TABLE "session" ADD COLUMN "provider_id" text;--> statement-breakpoint
ALTER TABLE "sso_provider" ADD CONSTRAINT "sso_provider_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "passkey" ADD CONSTRAINT "passkey_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "passkey" DROP COLUMN "publicKey";--> statement-breakpoint
ALTER TABLE "passkey" DROP COLUMN "userId";--> statement-breakpoint
-1
View File
@@ -1 +0,0 @@
ALTER TABLE "session" ADD COLUMN "provider_id" text;
+76 -326
View File
@@ -1,5 +1,5 @@
{
"id": "9106b694-50a6-4b6b-b33a-26d958844097",
"id": "90c26bd4-552c-445a-8491-487bcf705fa6",
"prevId": "29b53ca7-d603-4433-96f0-44d2df48ebdc",
"version": "7",
"dialect": "postgresql",
@@ -96,12 +96,8 @@
"name": "settings_default_storage_channel_id_storage_channel_id_fk",
"tableFrom": "settings",
"tableTo": "storage_channel",
"columnsFrom": [
"default_storage_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["default_storage_channel_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
@@ -111,9 +107,7 @@
"settings_name_unique": {
"name": "settings_name_unique",
"nullsNotDistinct": false,
"columns": [
"name"
]
"columns": ["name"]
}
},
"policies": {},
@@ -217,12 +211,8 @@
"name": "account_user_id_user_id_fk",
"tableFrom": "account",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -318,12 +308,8 @@
"name": "passkey_userId_user_id_fk",
"tableFrom": "passkey",
"tableTo": "user",
"columnsFrom": [
"userId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["userId"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -413,12 +399,8 @@
"name": "session_user_id_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -428,93 +410,7 @@
"session_token_unique": {
"name": "session_token_unique",
"nullsNotDistinct": false,
"columns": [
"token"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.sso_provider": {
"name": "sso_provider",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"issuer": {
"name": "issuer",
"type": "text",
"primaryKey": false,
"notNull": true
},
"oidc_config": {
"name": "oidc_config",
"type": "json",
"primaryKey": false,
"notNull": false
},
"saml_config": {
"name": "saml_config",
"type": "json",
"primaryKey": false,
"notNull": false
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"organization_id": {
"name": "organization_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"domain": {
"name": "domain",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"sso_provider_user_id_user_id_fk": {
"name": "sso_provider_user_id_user_id_fk",
"tableFrom": "sso_provider",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"sso_provider_provider_id_unique": {
"name": "sso_provider_provider_id_unique",
"nullsNotDistinct": false,
"columns": [
"provider_id"
]
"columns": ["token"]
}
},
"policies": {},
@@ -557,12 +453,8 @@
"name": "two_factor_user_id_user_id_fk",
"tableFrom": "two_factor",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -686,9 +578,7 @@
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
"columns": ["email"]
}
},
"policies": {},
@@ -814,9 +704,7 @@
"organization_slug_unique": {
"name": "organization_slug_unique",
"nullsNotDistinct": false,
"columns": [
"slug"
]
"columns": ["slug"]
}
},
"policies": {},
@@ -878,12 +766,8 @@
"name": "member_organization_id_organization_id_fk",
"tableFrom": "member",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -891,12 +775,8 @@
"name": "member_user_id_user_id_fk",
"tableFrom": "member",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -980,12 +860,8 @@
"name": "invitation_organization_id_organization_id_fk",
"tableFrom": "invitation",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -993,12 +869,8 @@
"name": "invitation_inviter_id_user_id_fk",
"tableFrom": "invitation",
"tableTo": "user",
"columnsFrom": [
"inviter_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["inviter_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1071,12 +943,8 @@
"name": "projects_organization_id_organization_id_fk",
"tableFrom": "projects",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1086,9 +954,7 @@
"projects_slug_unique": {
"name": "projects_slug_unique",
"nullsNotDistinct": false,
"columns": [
"slug"
]
"columns": ["slug"]
}
},
"policies": {},
@@ -1165,12 +1031,8 @@
"name": "backups_database_id_databases_id_fk",
"tableFrom": "backups",
"tableTo": "databases",
"columnsFrom": [
"database_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["database_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1281,12 +1143,8 @@
"name": "databases_agent_id_agents_id_fk",
"tableFrom": "databases",
"tableTo": "agents",
"columnsFrom": [
"agent_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["agent_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -1294,12 +1152,8 @@
"name": "databases_project_id_projects_id_fk",
"tableFrom": "databases",
"tableTo": "projects",
"columnsFrom": [
"project_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["project_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
@@ -1373,12 +1227,8 @@
"name": "restorations_backup_storage_id_backup_storage_id_fk",
"tableFrom": "restorations",
"tableTo": "backup_storage",
"columnsFrom": [
"backup_storage_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["backup_storage_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -1386,12 +1236,8 @@
"name": "restorations_backup_id_backups_id_fk",
"tableFrom": "restorations",
"tableTo": "backups",
"columnsFrom": [
"backup_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["backup_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -1399,12 +1245,8 @@
"name": "restorations_database_id_databases_id_fk",
"tableFrom": "restorations",
"tableTo": "databases",
"columnsFrom": [
"database_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["database_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1507,12 +1349,8 @@
"name": "retention_policies_database_id_databases_id_fk",
"tableFrom": "retention_policies",
"tableTo": "databases",
"columnsFrom": [
"database_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["database_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1598,9 +1436,7 @@
"agents_slug_unique": {
"name": "agents_slug_unique",
"nullsNotDistinct": false,
"columns": [
"slug"
]
"columns": ["slug"]
}
},
"policies": {},
@@ -1676,12 +1512,8 @@
"name": "notification_channel_organization_id_organization_id_fk",
"tableFrom": "notification_channel",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1715,12 +1547,8 @@
"name": "organization_notification_channels_organization_id_organization_id_fk",
"tableFrom": "organization_notification_channels",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -1728,12 +1556,8 @@
"name": "organization_notification_channels_notification_channel_id_notification_channel_id_fk",
"tableFrom": "organization_notification_channels",
"tableTo": "notification_channel",
"columnsFrom": [
"notification_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["notification_channel_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1743,10 +1567,7 @@
"organization_notification_channels_organization_id_notification_channel_id_unique": {
"name": "organization_notification_channels_organization_id_notification_channel_id_unique",
"nullsNotDistinct": false,
"columns": [
"organization_id",
"notification_channel_id"
]
"columns": ["organization_id", "notification_channel_id"]
}
},
"policies": {},
@@ -1816,12 +1637,8 @@
"name": "alert_policy_notification_channel_id_notification_channel_id_fk",
"tableFrom": "alert_policy",
"tableTo": "notification_channel",
"columnsFrom": [
"notification_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["notification_channel_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -1829,12 +1646,8 @@
"name": "alert_policy_database_id_databases_id_fk",
"tableFrom": "alert_policy",
"tableTo": "databases",
"columnsFrom": [
"database_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["database_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -1993,12 +1806,8 @@
"name": "organization_storage_channels_organization_id_organization_id_fk",
"tableFrom": "organization_storage_channels",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -2006,12 +1815,8 @@
"name": "organization_storage_channels_storage_channel_id_storage_channel_id_fk",
"tableFrom": "organization_storage_channels",
"tableTo": "storage_channel",
"columnsFrom": [
"storage_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["storage_channel_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -2021,10 +1826,7 @@
"organization_storage_channels_organization_id_storage_channel_id_unique": {
"name": "organization_storage_channels_organization_id_storage_channel_id_unique",
"nullsNotDistinct": false,
"columns": [
"organization_id",
"storage_channel_id"
]
"columns": ["organization_id", "storage_channel_id"]
}
},
"policies": {},
@@ -2100,12 +1902,8 @@
"name": "storage_channel_organization_id_organization_id_fk",
"tableFrom": "storage_channel",
"tableTo": "organization",
"columnsFrom": [
"organization_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -2172,12 +1970,8 @@
"name": "storage_policy_storage_channel_id_storage_channel_id_fk",
"tableFrom": "storage_policy",
"tableTo": "storage_channel",
"columnsFrom": [
"storage_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["storage_channel_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -2185,12 +1979,8 @@
"name": "storage_policy_database_id_databases_id_fk",
"tableFrom": "storage_policy",
"tableTo": "databases",
"columnsFrom": [
"database_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["database_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -2276,12 +2066,8 @@
"name": "backup_storage_backup_id_backups_id_fk",
"tableFrom": "backup_storage",
"tableTo": "backups",
"columnsFrom": [
"backup_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["backup_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
@@ -2289,12 +2075,8 @@
"name": "backup_storage_storage_channel_id_storage_channel_id_fk",
"tableFrom": "backup_storage",
"tableTo": "storage_channel",
"columnsFrom": [
"storage_channel_id"
],
"columnsTo": [
"id"
],
"columnsFrom": ["storage_channel_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
@@ -2310,20 +2092,12 @@
"public.user_themes": {
"name": "user_themes",
"schema": "public",
"values": [
"light",
"dark",
"system"
]
"values": ["light", "dark", "system"]
},
"public.retention_policy_type": {
"name": "retention_policy_type",
"schema": "public",
"values": [
"count",
"days",
"gfs"
]
"values": ["count", "days", "gfs"]
},
"public.provider_kind": {
"name": "provider_kind",
@@ -2352,56 +2126,32 @@
"public.level": {
"name": "level",
"schema": "public",
"values": [
"critical",
"warning",
"info"
]
"values": ["critical", "warning", "info"]
},
"public.provider_storage_kind": {
"name": "provider_storage_kind",
"schema": "public",
"values": [
"local",
"s3",
"google-drive"
]
"values": ["local", "s3", "google-drive"]
},
"public.backup_storage_status": {
"name": "backup_storage_status",
"schema": "public",
"values": [
"pending",
"success",
"failed"
]
"values": ["pending", "success", "failed"]
},
"public.dbms_status": {
"name": "dbms_status",
"schema": "public",
"values": [
"postgresql",
"mysql",
"mongodb"
]
"values": ["postgresql", "mysql", "mongodb", "sqlite"]
},
"public.status": {
"name": "status",
"schema": "public",
"values": [
"waiting",
"ongoing",
"failed",
"success"
]
"values": ["waiting", "ongoing", "failed", "success"]
},
"public.type_storage": {
"name": "type_storage",
"schema": "public",
"values": [
"local",
"s3"
]
"values": ["local", "s3"]
}
},
"schemas": {},
@@ -2414,4 +2164,4 @@
"schemas": {},
"tables": {}
}
}
}
+12 -5
View File
@@ -1,6 +1,6 @@
{
"id": "fc5d3d01-2097-4498-b5b0-525eb5f8417c",
"prevId": "9106b694-50a6-4b6b-b33a-26d958844097",
"id": "d26e1e78-ce2d-4084-bceb-c9e058a2b610",
"prevId": "90c26bd4-552c-445a-8491-487bcf705fa6",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -262,8 +262,8 @@
"primaryKey": false,
"notNull": true
},
"credential_i_d": {
"name": "credential_i_d",
"credential_id": {
"name": "credential_id",
"type": "text",
"primaryKey": false,
"notNull": true
@@ -381,6 +381,12 @@
"primaryKey": false,
"notNull": true
},
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"impersonated_by": {
"name": "impersonated_by",
"type": "text",
@@ -2388,7 +2394,8 @@
"values": [
"postgresql",
"mysql",
"mongodb"
"mongodb",
"sqlite"
]
},
"public.status": {
File diff suppressed because it is too large Load Diff
+4 -11
View File
@@ -243,22 +243,15 @@
{
"idx": 34,
"version": "7",
"when": 1770991368921,
"tag": "0034_vengeful_blacklash",
"when": 1771790675240,
"tag": "0034_lush_speed",
"breakpoints": true
},
{
"idx": 35,
"version": "7",
"when": 1770993283219,
"tag": "0035_windy_shockwave",
"breakpoints": true
},
{
"idx": 36,
"version": "7",
"when": 1771842940506,
"tag": "0036_left_longshot",
"when": 1771922367910,
"tag": "0035_late_young_avengers",
"breakpoints": true
}
]
+126 -123
View File
@@ -1,175 +1,178 @@
import {relations} from "drizzle-orm";
import {boolean, integer, pgEnum, json, pgTable, text, timestamp, uuid} from "drizzle-orm/pg-core";
import {createSelectSchema} from "drizzle-zod";
import {z} from "zod";
import {project} from "./06_project";
import {member} from "@/db/schema/04_member";
import {invitation} from "@/db/schema/05_invitation";
import {organization} from "@/db/schema/03_organization";
import {Account as BetterAuthAccount} from "better-auth";
import {timestamps} from "@/db/schema/00_common";
import { relations } from "drizzle-orm";
import {
boolean,
integer,
pgEnum,
json,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { createSelectSchema } from "drizzle-zod";
import { z } from "zod";
import { project } from "./06_project";
import { member } from "@/db/schema/04_member";
import { invitation } from "@/db/schema/05_invitation";
import { organization } from "@/db/schema/03_organization";
import { Account as BetterAuthAccount } from "better-auth";
import { timestamps } from "@/db/schema/00_common";
export const userThemeEnum = pgEnum("user_themes", ["light", "dark", "system"]);
export const user = pgTable("user", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
role: text("role"),
theme: userThemeEnum().notNull().default("light"),
banned: boolean("banned"),
banReason: text("ban_reason"),
banExpires: timestamp("ban_expires"),
lastConnectedAt: timestamp(),
lastChangedPasswordAt: timestamp(),
twoFactorEnabled: boolean("two_factor_enabled").default(false),
...timestamps
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
role: text("role"),
theme: userThemeEnum().notNull().default("light"),
banned: boolean("banned"),
banReason: text("ban_reason"),
banExpires: timestamp("ban_expires"),
lastConnectedAt: timestamp(),
lastChangedPasswordAt: timestamp(),
twoFactorEnabled: boolean("two_factor_enabled").default(false),
...timestamps,
});
export const session = pgTable("session", {
id: uuid("id").defaultRandom().primaryKey(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: uuid("user_id")
.notNull()
.references(() => user.id, {onDelete: "cascade"}),
providerId: text("provider_id"),
impersonatedBy: text("impersonated_by"), //id or name ????
activeOrganizationId: text("active_organization_id"),
...timestamps
id: uuid("id").defaultRandom().primaryKey(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: uuid("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
providerId: text("provider_id"),
impersonatedBy: text("impersonated_by"), //id or name ????
activeOrganizationId: text("active_organization_id"),
...timestamps,
});
export const account = pgTable("account", {
id: uuid("id").defaultRandom().primaryKey(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, {onDelete: "cascade"}),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
...timestamps
id: uuid("id").defaultRandom().primaryKey(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
...timestamps,
});
export const verification = pgTable("verification", {
id: uuid("id").defaultRandom().primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
...timestamps
id: uuid("id").defaultRandom().primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
...timestamps,
});
export const passkey = pgTable("passkey", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name"),
publicKey: text("public_key").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
credentialID: text("credential_i_d").notNull(),
counter: integer("counter").notNull(),
deviceType: text("device_type").notNull(),
backedUp: boolean("backed_up").notNull(),
transports: text("transports"),
aaguid: text("aaguid"),
...timestamps
id: uuid("id").defaultRandom().primaryKey(),
name: text("name"),
publicKey: text("public_key").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
credentialId: text("credential_id").notNull(),
counter: integer("counter").notNull(),
deviceType: text("device_type").notNull(),
backedUp: boolean("backed_up").notNull(),
transports: text("transports"),
aaguid: text("aaguid"),
...timestamps,
});
export const twoFactor = pgTable("two_factor", {
id: uuid().defaultRandom().primaryKey(),
secret: text("secret").notNull(),
backupCodes: text("backup_codes").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, {onDelete: "cascade"}),
id: uuid().defaultRandom().primaryKey(),
secret: text("secret").notNull(),
backupCodes: text("backup_codes").notNull(),
userId: uuid("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
});
export const ssoProvider = pgTable("sso_provider", {
id: uuid("id").defaultRandom().primaryKey(),
issuer: text("issuer").notNull(),
oidcConfig: json("oidc_config"),
samlConfig: json("saml_config"),
userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }),
providerId: text("provider_id").notNull().unique(),
organizationId: text("organization_id"),
domain: text("domain").notNull(),
id: uuid("id").defaultRandom().primaryKey(),
issuer: text("issuer").notNull(),
oidcConfig: json("oidc_config"),
samlConfig: json("saml_config"),
userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }),
providerId: text("provider_id").notNull().unique(),
organizationId: text("organization_id"),
domain: text("domain").notNull(),
});
export const userRelations = relations(user, ({many}) => ({
sessions: many(session),
accounts: many(account),
ssoProviders: many(ssoProvider),
memberships: many(member),
invitations: many(invitation),
passkeys: many(passkey),
export const userRelations = relations(user, ({ many }) => ({
sessions: many(session),
accounts: many(account),
ssoProviders: many(ssoProvider),
memberships: many(member),
invitations: many(invitation),
passkeys: many(passkey),
}));
export const sessionRelations = relations(session, ({one}) => ({
user: one(user, {
fields: [session.userId],
references: [user.id],
}),
export const sessionRelations = relations(session, ({ one }) => ({
user: one(user, {
fields: [session.userId],
references: [user.id],
}),
}));
export const accountRelations = relations(account, ({one}) => ({
user: one(user, {
fields: [account.userId],
references: [user.id],
}),
export const accountRelations = relations(account, ({ one }) => ({
user: one(user, {
fields: [account.userId],
references: [user.id],
}),
}));
export const ssoProviderRelations = relations(ssoProvider, ({ one }) => ({
user: one(user, {
fields: [ssoProvider.userId],
references: [user.id],
}),
user: one(user, {
fields: [ssoProvider.userId],
references: [user.id],
}),
}));
export const projectRelations = relations(project, ({one}) => ({
organization: one(organization, {
fields: [project.organizationId],
references: [organization.id],
}),
export const projectRelations = relations(project, ({ one }) => ({
organization: one(organization, {
fields: [project.organizationId],
references: [organization.id],
}),
}));
export const passkeyRelations = relations(passkey, ({ one }) => ({
user: one(user, {
fields: [passkey.userId],
references: [user.id],
}),
user: one(user, {
fields: [passkey.userId],
references: [user.id],
}),
}));
export const userSchema = createSelectSchema(user);
export type User = z.infer<typeof userSchema>;
export const userThemeEnumSchema = createSelectSchema(userThemeEnum)
export const userThemeEnumSchema = createSelectSchema(userThemeEnum);
export type UserThemeEnum = z.infer<typeof userThemeEnumSchema>;
export const sessionSchema = createSelectSchema(session);
export type Session = z.infer<typeof sessionSchema>;
export const accountSchema = createSelectSchema(account);
export type Account = z.infer<typeof accountSchema>;
type FixedAccount = Omit<BetterAuthAccount, 'updatedAt'> & {
updatedAt: Date | null;
type FixedAccount = Omit<BetterAuthAccount, "updatedAt"> & {
updatedAt: Date | null;
};
export type UserWithAccounts = User & {
accounts: FixedAccount[];
};
accounts: FixedAccount[];
};
-1
View File
@@ -9,7 +9,6 @@ import {timestamps} from "@/db/schema/00_common";
import {AlertPolicy, alertPolicy} from "@/db/schema/10_alert-policy";
import {StoragePolicy, storagePolicy} from "@/db/schema/13_storage-policy";
import {BackupStorage, backupStorage} from "@/db/schema/14_storage-backup";
import {storageChannel} from "@/db/schema/12_storage-channel";
export const database = pgTable("databases", {
id: uuid("id").primaryKey().defaultRandom(),
+1 -1
View File
@@ -2,7 +2,7 @@ import {pgEnum} from "drizzle-orm/pg-core";
import {createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const dbmsEnum = pgEnum("dbms_status", ["postgresql", "mysql", "mongodb"]);
export const dbmsEnum = pgEnum("dbms_status", ["postgresql", "mysql", "mongodb", "sqlite"]);
export const statusEnum = pgEnum("status", ["waiting", "ongoing", "failed", "success"]);
export const typeStorageEnum = pgEnum("type_storage", ["local", "s3"]);
+11 -9
View File
@@ -7,7 +7,6 @@ import {User, UserThemeEnum} from "@/db/schema/02_user";
export async function createUserDb(data: SignUpUser): Promise<User> {
const now = new Date();
const hashedPassword = await hashPassword(data.password);
const userId = crypto.randomUUID();
const [newUser] = await db.insert(drizzleDb.schemas.user).values({
@@ -21,14 +20,17 @@ export async function createUserDb(data: SignUpUser): Promise<User> {
theme: data.theme as UserThemeEnum,
}).returning();
await db.insert(drizzleDb.schemas.account).values({
providerId: "credential",
accountId: userId,
userId: userId,
password: hashedPassword,
createdAt: now,
updatedAt: now,
});
if (data.password) {
const hashedPassword = await hashPassword(data.password);
await db.insert(drizzleDb.schemas.account).values({
providerId: "credential",
accountId: userId,
userId: userId,
password: hashedPassword,
createdAt: now,
updatedAt: now,
});
}
return newUser
}