@@ -0,0 +1,2 @@
|
||||
CREATE UNIQUE INDEX `public_key_interface_unique` ON `clients_table` (`public_key`,`interface_id`);--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `users_table_email_unique` ON `users_table` (`email`);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,13 @@
|
||||
"when": 1780035570366,
|
||||
"tag": "0005_clumsy_korg",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "6",
|
||||
"when": 1782122902196,
|
||||
"tag": "0006_clear_leech",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,64 +1,75 @@
|
||||
import { sql, relations } from 'drizzle-orm';
|
||||
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
import { int, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { wgInterface } from '#db/repositories/interface/schema';
|
||||
import { oneTimeLink } from '#db/repositories/oneTimeLink/schema';
|
||||
import { user } from '#db/repositories/user/schema';
|
||||
import { wgInterface } from '../interface/schema';
|
||||
import { oneTimeLink } from '../oneTimeLink/schema';
|
||||
import { user } from '../user/schema';
|
||||
|
||||
/** null means use value from userConfig */
|
||||
|
||||
export const client = sqliteTable('clients_table', {
|
||||
id: int().primaryKey({ autoIncrement: true }),
|
||||
userId: int('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, {
|
||||
onDelete: 'restrict',
|
||||
onUpdate: 'cascade',
|
||||
}),
|
||||
interfaceId: text('interface_id')
|
||||
.notNull()
|
||||
.references(() => wgInterface.name, {
|
||||
onDelete: 'cascade',
|
||||
onUpdate: 'cascade',
|
||||
}),
|
||||
name: text().notNull(),
|
||||
ipv4Address: text('ipv4_address').notNull().unique(),
|
||||
ipv6Address: text('ipv6_address').notNull().unique(),
|
||||
preUp: text('pre_up').default('').notNull(),
|
||||
postUp: text('post_up').default('').notNull(),
|
||||
preDown: text('pre_down').default('').notNull(),
|
||||
postDown: text('post_down').default('').notNull(),
|
||||
privateKey: text('private_key').notNull(),
|
||||
publicKey: text('public_key').notNull(),
|
||||
preSharedKey: text('pre_shared_key').notNull(),
|
||||
expiresAt: text('expires_at'),
|
||||
allowedIps: text('allowed_ips', { mode: 'json' }).$type<string[]>(),
|
||||
serverAllowedIps: text('server_allowed_ips', { mode: 'json' })
|
||||
.$type<string[]>()
|
||||
.notNull(),
|
||||
// Firewall-enforced allowed IPs (null = use allowedIps)
|
||||
firewallIps: text('firewall_ips', { mode: 'json' }).$type<string[] | null>(),
|
||||
persistentKeepalive: int('persistent_keepalive').notNull(),
|
||||
mtu: int().notNull(),
|
||||
jC: int('j_c'),
|
||||
jMin: int('j_min'),
|
||||
jMax: int('j_max'),
|
||||
i1: text(),
|
||||
i2: text(),
|
||||
i3: text(),
|
||||
i4: text(),
|
||||
i5: text(),
|
||||
dns: text({ mode: 'json' }).$type<string[]>(),
|
||||
serverEndpoint: text('server_endpoint'),
|
||||
enabled: int({ mode: 'boolean' }).notNull(),
|
||||
createdAt: text('created_at')
|
||||
.notNull()
|
||||
.default(sql`(CURRENT_TIMESTAMP)`),
|
||||
updatedAt: text('updated_at')
|
||||
.notNull()
|
||||
.default(sql`(CURRENT_TIMESTAMP)`)
|
||||
.$onUpdate(() => sql`(CURRENT_TIMESTAMP)`),
|
||||
});
|
||||
export const client = sqliteTable(
|
||||
'clients_table',
|
||||
{
|
||||
id: int().primaryKey({ autoIncrement: true }),
|
||||
userId: int('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, {
|
||||
onDelete: 'restrict',
|
||||
onUpdate: 'cascade',
|
||||
}),
|
||||
interfaceId: text('interface_id')
|
||||
.notNull()
|
||||
.references(() => wgInterface.name, {
|
||||
onDelete: 'cascade',
|
||||
onUpdate: 'cascade',
|
||||
}),
|
||||
name: text().notNull(),
|
||||
ipv4Address: text('ipv4_address').notNull().unique(),
|
||||
ipv6Address: text('ipv6_address').notNull().unique(),
|
||||
preUp: text('pre_up').default('').notNull(),
|
||||
postUp: text('post_up').default('').notNull(),
|
||||
preDown: text('pre_down').default('').notNull(),
|
||||
postDown: text('post_down').default('').notNull(),
|
||||
privateKey: text('private_key').notNull(),
|
||||
publicKey: text('public_key').notNull(),
|
||||
preSharedKey: text('pre_shared_key').notNull(),
|
||||
expiresAt: text('expires_at'),
|
||||
allowedIps: text('allowed_ips', { mode: 'json' }).$type<string[]>(),
|
||||
serverAllowedIps: text('server_allowed_ips', { mode: 'json' })
|
||||
.$type<string[]>()
|
||||
.notNull(),
|
||||
// Firewall-enforced allowed IPs (null = use allowedIps)
|
||||
firewallIps: text('firewall_ips', { mode: 'json' }).$type<
|
||||
string[] | null
|
||||
>(),
|
||||
persistentKeepalive: int('persistent_keepalive').notNull(),
|
||||
mtu: int().notNull(),
|
||||
jC: int('j_c'),
|
||||
jMin: int('j_min'),
|
||||
jMax: int('j_max'),
|
||||
i1: text(),
|
||||
i2: text(),
|
||||
i3: text(),
|
||||
i4: text(),
|
||||
i5: text(),
|
||||
dns: text({ mode: 'json' }).$type<string[]>(),
|
||||
serverEndpoint: text('server_endpoint'),
|
||||
enabled: int({ mode: 'boolean' }).notNull(),
|
||||
createdAt: text('created_at')
|
||||
.notNull()
|
||||
.default(sql`(CURRENT_TIMESTAMP)`),
|
||||
updatedAt: text('updated_at')
|
||||
.notNull()
|
||||
.default(sql`(CURRENT_TIMESTAMP)`)
|
||||
.$onUpdate(() => sql`(CURRENT_TIMESTAMP)`),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('public_key_interface_unique').on(
|
||||
table.publicKey,
|
||||
table.interfaceId
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
export const clientsRelations = relations(client, ({ one }) => ({
|
||||
oneTimeLink: one(oneTimeLink, {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { wgInterface } from '#db/repositories/interface/schema';
|
||||
import { wgInterface } from '../interface/schema';
|
||||
|
||||
export const hooks = sqliteTable('hooks_table', {
|
||||
/** same as `wgInterface.name` */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { sql, relations } from 'drizzle-orm';
|
||||
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { hooks } from '#db/repositories/hooks/schema';
|
||||
import { userConfig } from '#db/repositories/userConfig/schema';
|
||||
import { hooks } from '../hooks/schema';
|
||||
import { userConfig } from '../userConfig/schema';
|
||||
|
||||
// maybe support multiple interfaces in the future
|
||||
export const wgInterface = sqliteTable('interfaces_table', {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { sql, relations } from 'drizzle-orm';
|
||||
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { client } from '#db/repositories/client/schema';
|
||||
import { client } from '../client/schema';
|
||||
|
||||
export const oneTimeLink = sqliteTable('one_time_links_table', {
|
||||
/** same as `client.id` */
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { sql, relations } from 'drizzle-orm';
|
||||
import { int, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { client } from '#db/repositories/client/schema';
|
||||
import { client } from '../client/schema';
|
||||
|
||||
import type { Role } from '#shared/utils/permissions';
|
||||
import type { OAUTH_PROVIDER } from '#server/utils/oauth';
|
||||
|
||||
@@ -12,7 +13,7 @@ export const user = sqliteTable(
|
||||
username: text().notNull().unique(),
|
||||
/** `password == null` means password login disabled */
|
||||
password: text(),
|
||||
email: text(),
|
||||
email: text().unique(),
|
||||
name: text().notNull(),
|
||||
role: int().$type<Role>().notNull(),
|
||||
totpKey: text('totp_key'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { wgInterface } from '#db/repositories/interface/schema';
|
||||
import { wgInterface } from '../interface/schema';
|
||||
|
||||
// default* means clients store it themselves
|
||||
export const userConfig = sqliteTable('user_configs_table', {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export * from '#db/repositories/client/schema';
|
||||
export * from '#db/repositories/general/schema';
|
||||
export * from '#db/repositories/hooks/schema';
|
||||
export * from '#db/repositories/interface/schema';
|
||||
export * from '#db/repositories/oneTimeLink/schema';
|
||||
export * from '#db/repositories/user/schema';
|
||||
export * from '#db/repositories/userConfig/schema';
|
||||
// ! Do not use Path Aliases in this or any of these files
|
||||
export * from './repositories/client/schema';
|
||||
export * from './repositories/general/schema';
|
||||
export * from './repositories/hooks/schema';
|
||||
export * from './repositories/interface/schema';
|
||||
export * from './repositories/oneTimeLink/schema';
|
||||
export * from './repositories/user/schema';
|
||||
export * from './repositories/userConfig/schema';
|
||||
|
||||
@@ -69,6 +69,7 @@ async function migrate() {
|
||||
if (e instanceof Error) {
|
||||
DB_DEBUG('Failed to migrate database:', e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,14 @@ const nullObject = new Proxy(
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
let provider = nullObject as never as DBServiceType;
|
||||
|
||||
connect().then((db) => {
|
||||
provider = db;
|
||||
WireGuard.Startup();
|
||||
});
|
||||
connect()
|
||||
.then((db) => {
|
||||
provider = db;
|
||||
WireGuard.Startup();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('Failed to connect to Database:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
export default provider;
|
||||
|
||||
Reference in New Issue
Block a user