From 31d00d838427e1107663b9bed1660d2faa7ed185 Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Wed, 20 Mar 2024 16:19:58 +0700 Subject: [PATCH] feat: add user file schema --- drizzle/0005_fine_turbo.sql | 12 + drizzle/meta/0005_snapshot.json | 719 ++++++++++++++++++++++++++++++++ drizzle/meta/_journal.json | 7 + src/db/schema-database.ts | 119 ++++++ src/db/schema-user.ts | 71 ++++ src/db/schema.ts | 165 +------- 6 files changed, 930 insertions(+), 163 deletions(-) create mode 100644 drizzle/0005_fine_turbo.sql create mode 100644 drizzle/meta/0005_snapshot.json create mode 100644 src/db/schema-database.ts create mode 100644 src/db/schema-user.ts diff --git a/drizzle/0005_fine_turbo.sql b/drizzle/0005_fine_turbo.sql new file mode 100644 index 00000000..9e771c75 --- /dev/null +++ b/drizzle/0005_fine_turbo.sql @@ -0,0 +1,12 @@ +CREATE TABLE `user_file` ( + `id` text PRIMARY KEY NOT NULL, + `user_id` text, + `hashed` text, + `path` text, + `filename` text, + `size_in_byte` integer, + `created_at` integer +); +--> statement-breakpoint +ALTER TABLE user ADD `storage_usage` integer DEFAULT 0;--> statement-breakpoint +CREATE INDEX `user_file_index` ON `user_file` (`user_id`,`created_at`); \ No newline at end of file diff --git a/drizzle/meta/0005_snapshot.json b/drizzle/meta/0005_snapshot.json new file mode 100644 index 00000000..763e6f5d --- /dev/null +++ b/drizzle/meta/0005_snapshot.json @@ -0,0 +1,719 @@ +{ + "version": "5", + "dialect": "sqlite", + "id": "d1ecb245-422d-4b5e-8dbc-a78735dd43dd", + "prevId": "da88f65b-8df2-40d8-b7c8-33ffb65a7d2c", + "tables": { + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "picture": { + "name": "picture", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "storage_usage": { + "name": "storage_usage", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user_file": { + "name": "user_file", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hashed": { + "name": "hashed", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "size_in_byte": { + "name": "size_in_byte", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_file_index": { + "name": "user_file_index", + "columns": [ + "user_id", + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user_auth": { + "name": "user_auth", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "user_auth_provider_provider_id_unique": { + "name": "user_auth_provider_provider_id_unique", + "columns": [ + "provider", + "provider_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user_session": { + "name": "user_session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth_id": { + "name": "auth_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "blob", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "user_session_expire_idx": { + "name": "user_session_expire_idx", + "columns": [ + "expires_at" + ], + "isUnique": false + }, + "user_session_auth_id_idx": { + "name": "user_session_auth_id_idx", + "columns": [ + "auth_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "user_session_user_id_user_id_fk": { + "name": "user_session_user_id_user_id_fk", + "tableFrom": "user_session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "database": { + "name": "database", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'gray'" + }, + "driver": { + "name": "driver", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'turso'" + }, + "host": { + "name": "host", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "database_user_idx": { + "name": "database_user_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "database_user_id_user_id_fk": { + "name": "database_user_id_user_id_fk", + "tableFrom": "database", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "database_role": { + "name": "database_role", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "database_id": { + "name": "database_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "can_execute_query": { + "name": "can_execute_query", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "is_owner": { + "name": "is_owner", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "database_role_idx": { + "name": "database_role_idx", + "columns": [ + "database_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "database_role_database_id_database_id_fk": { + "name": "database_role_database_id_database_id_fk", + "tableFrom": "database_role", + "tableTo": "database", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_role_created_by_user_id_fk": { + "name": "database_role_created_by_user_id_fk", + "tableFrom": "database_role", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_role_updated_by_user_id_fk": { + "name": "database_role_updated_by_user_id_fk", + "tableFrom": "database_role", + "tableTo": "user", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "database_role_permission": { + "name": "database_role_permission", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "role_id": { + "name": "role_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access": { + "name": "access", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "table_name": { + "name": "table_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "column_name": { + "name": "column_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "role_permission_table_idx": { + "name": "role_permission_table_idx", + "columns": [ + "role_id", + "table_name" + ], + "isUnique": false + } + }, + "foreignKeys": { + "database_role_permission_role_id_database_role_id_fk": { + "name": "database_role_permission_role_id_database_role_id_fk", + "tableFrom": "database_role_permission", + "tableTo": "database_role", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_role_permission_created_by_user_id_fk": { + "name": "database_role_permission_created_by_user_id_fk", + "tableFrom": "database_role_permission", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_role_permission_updated_by_user_id_fk": { + "name": "database_role_permission_updated_by_user_id_fk", + "tableFrom": "database_role_permission", + "tableTo": "user", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "database_user_role": { + "name": "database_user_role", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "database_id": { + "name": "database_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role_id": { + "name": "role_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "database_user_role_user_id_user_id_fk": { + "name": "database_user_role_user_id_user_id_fk", + "tableFrom": "database_user_role", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_user_role_database_id_database_id_fk": { + "name": "database_user_role_database_id_database_id_fk", + "tableFrom": "database_user_role", + "tableTo": "database", + "columnsFrom": [ + "database_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_user_role_role_id_database_role_id_fk": { + "name": "database_user_role_role_id_database_role_id_fk", + "tableFrom": "database_user_role", + "tableTo": "database_role", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "database_user_role_created_by_user_id_fk": { + "name": "database_user_role_created_by_user_id_fk", + "tableFrom": "database_user_role", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "database_user_role_database_id_user_id_pk": { + "columns": [ + "database_id", + "user_id" + ], + "name": "database_user_role_database_id_user_id_pk" + } + }, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index e8744d7b..9569b2df 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -36,6 +36,13 @@ "when": 1710766406033, "tag": "0004_misty_the_professor", "breakpoints": true + }, + { + "idx": 5, + "version": "5", + "when": 1710906389797, + "tag": "0005_fine_turbo", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/schema-database.ts b/src/db/schema-database.ts new file mode 100644 index 00000000..cabb2291 --- /dev/null +++ b/src/db/schema-database.ts @@ -0,0 +1,119 @@ +import { relations } from "drizzle-orm"; +import { + index, + int, + primaryKey, + sqliteTable, + text, +} from "drizzle-orm/sqlite-core"; +import { user } from "./schema-user"; + +export type DatabaseRoleType = "table"; +export type DatabaseRoleAccess = + | "write" + | "read" + | "delete" + | "write-delete" + | "column-read" + | "column-denied"; + +export const database = sqliteTable( + "database", + { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => user.id), + name: text("name"), + description: text("description"), + color: text("color").default("gray"), + driver: text("driver").default("turso"), + host: text("host"), + token: text("token"), + createdAt: int("created_at"), + deletedAt: int("deleted_at"), + }, + (table) => { + return { databaseUserIdx: index("database_user_idx").on(table.userId) }; + } +); + +export const database_role = sqliteTable( + "database_role", + { + id: text("id").primaryKey(), + databaseId: text("database_id") + .notNull() + .references(() => database.id), + name: text("name"), + canExecuteQuery: int("can_execute_query").default(0), + isOwner: int("is_owner").default(0), + createdBy: text("created_by").references(() => user.id), + createdAt: int("created_at"), + updatedBy: text("updated_by").references(() => user.id), + updatedAt: int("updated_at"), + }, + (table) => { + return { + databaseRoleIdx: index("database_role_idx").on(table.databaseId), + }; + } +); + +export const database_user_role = sqliteTable( + "database_user_role", + { + userId: text("user_id").references(() => user.id), + databaseId: text("database_id").references(() => database.id), + roleId: text("role_id").references(() => database_role.id), + createdAt: int("created_at"), + createdBy: text("created_by").references(() => user.id), + }, + (table) => { + return { pk: primaryKey({ columns: [table.databaseId, table.userId] }) }; + } +); + +export const database_role_permission = sqliteTable( + "database_role_permission", + { + id: text("id").primaryKey(), + roleId: text("role_id") + .notNull() + .references(() => database_role.id), + + type: text("role").$type(), + access: text("access").$type(), + tableName: text("table_name"), + columnName: text("column_name"), + + createdBy: text("created_by").references(() => user.id), + createdAt: int("created_at"), + updatedBy: text("updated_by").references(() => user.id), + updatedAt: int("updated_at"), + }, + (table) => { + return { + databaseRoleIdx: index("role_permission_table_idx").on( + table.roleId, + table.tableName + ), + }; + } +); + +export const databaseRoleRelation = relations(database_role, ({ many }) => { + return { permissions: many(database_role_permission) }; +}); + +export const databaseRolePermissionRelation = relations( + database_role_permission, + ({ one }) => { + return { + role: one(database_role, { + fields: [database_role_permission.roleId], + references: [database_role.id], + }), + }; + } +); diff --git a/src/db/schema-user.ts b/src/db/schema-user.ts new file mode 100644 index 00000000..6d432999 --- /dev/null +++ b/src/db/schema-user.ts @@ -0,0 +1,71 @@ +import { sql } from "drizzle-orm"; +import { + blob, + index, + int, + sqliteTable, + text, + unique, +} from "drizzle-orm/sqlite-core"; + +export const user = sqliteTable("user", { + id: text("id").primaryKey(), + name: text("name"), + picture: text("picture"), + createdAt: text("created_at") + .notNull() + .default(sql`CURRENT_TIMESTAMP`), + email: text("email"), + storageUsage: int("storage_usage").default(0), +}); + +export const user_session = sqliteTable( + "user_session", + { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => user.id), + authId: text("auth_id"), + userAgent: text("user_agent"), + expiresAt: blob("expires_at", { mode: "bigint" }).notNull(), + }, + (table) => ({ + expireIdx: index("user_session_expire_idx").on(table.expiresAt), + authIdx: index("user_session_auth_id_idx").on(table.authId), + }) +); + +export const user_oauth = sqliteTable( + "user_auth", + { + id: text("id").primaryKey(), + userId: text("user_id"), + provider: text("provider"), + providerId: text("provider_id"), + createdAt: text("created_at") + .notNull() + .default(sql`CURRENT_TIMESTAMP`), + }, + (table) => ({ + providerUniqueId: unique().on(table.provider, table.providerId), + }) +); + +export const user_file = sqliteTable( + "user_file", + { + id: text("id").primaryKey(), + user_id: text("user_id"), + hashed: text("hashed"), + path: text("path"), + filename: text("filename"), + size_in_byte: int("size_in_byte"), + created_at: int("created_at"), + }, + (table) => { + return { + userFileIdx: index("user_file_index").on(table.user_id, table.created_at), + }; + } +); diff --git a/src/db/schema.ts b/src/db/schema.ts index 38c88569..48312250 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -1,163 +1,2 @@ -import { relations, sql } from "drizzle-orm"; -import { - blob, - index, - int, - primaryKey, - sqliteTable, - text, - unique, -} from "drizzle-orm/sqlite-core"; - -export type DatabaseRoleType = "table"; -export type DatabaseRoleAccess = - | "write" - | "read" - | "delete" - | "write-delete" - | "column-read" - | "column-denied"; - -export const user = sqliteTable("user", { - id: text("id").primaryKey(), - name: text("name"), - picture: text("picture"), - createdAt: text("created_at") - .notNull() - .default(sql`CURRENT_TIMESTAMP`), - email: text("email"), -}); - -export const user_session = sqliteTable( - "user_session", - { - id: text("id").primaryKey(), - userId: text("user_id") - .notNull() - .references(() => user.id), - authId: text("auth_id"), - userAgent: text("user_agent"), - expiresAt: blob("expires_at", { mode: "bigint" }).notNull(), - }, - (table) => ({ - expireIdx: index("user_session_expire_idx").on(table.expiresAt), - authIdx: index("user_session_auth_id_idx").on(table.authId), - }) -); - -export const user_oauth = sqliteTable( - "user_auth", - { - id: text("id").primaryKey(), - userId: text("user_id"), - provider: text("provider"), - providerId: text("provider_id"), - createdAt: text("created_at") - .notNull() - .default(sql`CURRENT_TIMESTAMP`), - }, - (table) => ({ - providerUniqueId: unique().on(table.provider, table.providerId), - }) -); - -export const database = sqliteTable( - "database", - { - id: text("id").primaryKey(), - userId: text("user_id") - .notNull() - .references(() => user.id), - name: text("name"), - description: text("description"), - color: text("color").default("gray"), - driver: text("driver").default("turso"), - host: text("host"), - token: text("token"), - createdAt: int("created_at"), - deletedAt: int("deleted_at"), - }, - (table) => { - return { databaseUserIdx: index("database_user_idx").on(table.userId) }; - } -); - -export const database_role = sqliteTable( - "database_role", - { - id: text("id").primaryKey(), - databaseId: text("database_id") - .notNull() - .references(() => database.id), - name: text("name"), - canExecuteQuery: int("can_execute_query").default(0), - isOwner: int("is_owner").default(0), - createdBy: text("created_by").references(() => user.id), - createdAt: int("created_at"), - updatedBy: text("updated_by").references(() => user.id), - updatedAt: int("updated_at"), - }, - (table) => { - return { - databaseRoleIdx: index("database_role_idx").on(table.databaseId), - }; - } -); - -export const database_user_role = sqliteTable( - "database_user_role", - { - userId: text("user_id").references(() => user.id), - databaseId: text("database_id").references(() => database.id), - roleId: text("role_id").references(() => database_role.id), - createdAt: int("created_at"), - createdBy: text("created_by").references(() => user.id), - }, - (table) => { - return { pk: primaryKey({ columns: [table.databaseId, table.userId] }) }; - } -); - -export const database_role_permission = sqliteTable( - "database_role_permission", - { - id: text("id").primaryKey(), - roleId: text("role_id") - .notNull() - .references(() => database_role.id), - - type: text("role").$type(), - access: text("access").$type(), - tableName: text("table_name"), - columnName: text("column_name"), - - createdBy: text("created_by").references(() => user.id), - createdAt: int("created_at"), - updatedBy: text("updated_by").references(() => user.id), - updatedAt: int("updated_at"), - }, - (table) => { - return { - databaseRoleIdx: index("role_permission_table_idx").on( - table.roleId, - table.tableName - ), - }; - } -); - -export const databaseRoleRelation = relations(database_role, ({ many }) => { - return { permissions: many(database_role_permission) }; -}); - -export const databaseRolePermissionRelation = relations( - database_role_permission, - ({ one }) => { - return { - role: one(database_role, { - fields: [database_role_permission.roleId], - references: [database_role.id], - }), - }; - } -); +export * from "./schema-user"; +export * from "./schema-database";