NORY-41: refactor drizzle schema to match snake_case @ory/client types
This commit is contained in:
parent
8032f11d30
commit
a4957fc627
4 changed files with 926 additions and 906 deletions
File diff suppressed because it is too large
Load diff
18
dashboard/src/db/convert-case.ts
Normal file
18
dashboard/src/db/convert-case.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
const fs = require('fs');
|
||||
const filepath = 'src/db/schema.ts';
|
||||
|
||||
const schemaContent = fs.readFileSync(filepath, 'utf-8');
|
||||
|
||||
const updatedSchema = schemaContent.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()
|
||||
.replace(/primary_key/g, 'primaryKey')
|
||||
.replace(/unique_index/g, 'uniqueIndex')
|
||||
.replace(/not_null/g, 'notNull')
|
||||
.replace(/nulls_first/g, 'nullsFirst')
|
||||
.replace(/nulls_last/g, 'nullsLast')
|
||||
.replace(/foreign_key/g, 'foreignKey')
|
||||
.replace(/on_update/g, 'onUpdate')
|
||||
.replace(/on_delete/g, 'onDelete')
|
||||
.replace(/pg_table/g, 'pgTable')
|
||||
.replace(/foreign_columns/g, 'foreignColumns');
|
||||
|
||||
fs.writeFileSync(filepath, updatedSchema);
|
|
@ -17,35 +17,35 @@ import {
|
|||
} from 'drizzle-orm/pg-core';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
export const schemaMigration = pgTable('schema_migration', {
|
||||
export const schema_migration = pgTable('schema_migration', {
|
||||
version: varchar({ length: 48 }).notNull(),
|
||||
versionSelf: integer('version_self').default(0).notNull(),
|
||||
version_self: integer('version_self').default(0).notNull(),
|
||||
}, (table) => [
|
||||
uniqueIndex('schema_migration_version_idx').using('btree', table.version.asc().nullsLast().op('text_ops')),
|
||||
index('schema_migration_version_self_idx').using('btree', table.versionSelf.asc().nullsLast().op('int4_ops')),
|
||||
index('schema_migration_version_self_idx').using('btree', table.version_self.asc().nullsLast().op('int4_ops')),
|
||||
]);
|
||||
|
||||
export const identityCredentials = pgTable('identity_credentials', {
|
||||
export const identity_credentials = pgTable('identity_credentials', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
config: jsonb().notNull(),
|
||||
identityCredentialTypeId: uuid('identity_credential_type_id').notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
identity_credential_type_id: uuid('identity_credential_type_id').notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
version: integer().default(0).notNull(),
|
||||
}, (table) => [
|
||||
index('identity_credentials_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credentials_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credentials_nid_identity_id_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credentials_nid_identity_id_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_credentials_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityCredentialTypeId],
|
||||
foreignColumns: [identityCredentialTypes.id],
|
||||
columns: [table.identity_credential_type_id],
|
||||
foreignColumns: [identity_credential_types.id],
|
||||
name: 'identity_credentials_identity_credential_type_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -55,33 +55,33 @@ export const identityCredentials = pgTable('identity_credentials', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityCredentialTypes = pgTable('identity_credential_types', {
|
||||
export const identity_credential_types = pgTable('identity_credential_types', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
name: varchar({ length: 32 }).notNull(),
|
||||
}, (table) => [
|
||||
uniqueIndex('identity_credential_types_name_idx').using('btree', table.name.asc().nullsLast().op('text_ops')),
|
||||
]);
|
||||
|
||||
export const selfserviceLoginFlows = pgTable('selfservice_login_flows', {
|
||||
export const selfservice_login_flows = pgTable('selfservice_login_flows', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
requestUrl: text('request_url').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
activeMethod: varchar('active_method', { length: 32 }).notNull(),
|
||||
csrfToken: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
request_url: text('request_url').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
active_method: varchar('active_method', { length: 32 }).notNull(),
|
||||
csrf_token: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
forced: boolean().default(false).notNull(),
|
||||
type: varchar({ length: 16 }).default('browser').notNull(),
|
||||
ui: jsonb(),
|
||||
nid: uuid(),
|
||||
requestedAal: varchar('requested_aal', { length: 4 }).default('aal1').notNull(),
|
||||
internalContext: jsonb('internal_context').notNull(),
|
||||
oauth2LoginChallenge: uuid('oauth2_login_challenge'),
|
||||
oauth2LoginChallengeData: text('oauth2_login_challenge_data'),
|
||||
requested_aal: varchar('requested_aal', { length: 4 }).default('aal1').notNull(),
|
||||
internal_context: jsonb('internal_context').notNull(),
|
||||
oauth2login_challenge: uuid('oauth2_login_challenge'),
|
||||
oauth2login_challenge_data: text('oauth2_login_challenge_data'),
|
||||
state: varchar({ length: 255 }),
|
||||
submitCount: integer('submit_count').default(0).notNull(),
|
||||
organizationId: uuid('organization_id'),
|
||||
submit_count: integer('submit_count').default(0).notNull(),
|
||||
organization_id: uuid('organization_id'),
|
||||
}, (table) => [
|
||||
index('selfservice_login_flows_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_login_flows_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
|
@ -94,28 +94,28 @@ export const selfserviceLoginFlows = pgTable('selfservice_login_flows', {
|
|||
|
||||
export const networks = pgTable('networks', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const selfserviceRegistrationFlows = pgTable('selfservice_registration_flows', {
|
||||
export const selfservice_registration_flows = pgTable('selfservice_registration_flows', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
requestUrl: text('request_url').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
activeMethod: varchar('active_method', { length: 32 }).notNull(),
|
||||
csrfToken: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
request_url: text('request_url').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
active_method: varchar('active_method', { length: 32 }).notNull(),
|
||||
csrf_token: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
type: varchar({ length: 16 }).default('browser').notNull(),
|
||||
ui: jsonb(),
|
||||
nid: uuid(),
|
||||
internalContext: jsonb('internal_context').notNull(),
|
||||
oauth2LoginChallenge: uuid('oauth2_login_challenge'),
|
||||
oauth2LoginChallengeData: text('oauth2_login_challenge_data'),
|
||||
internal_context: jsonb('internal_context').notNull(),
|
||||
oauth2login_challenge: uuid('oauth2_login_challenge'),
|
||||
oauth2login_challenge_data: text('oauth2_login_challenge_data'),
|
||||
state: varchar({ length: 255 }),
|
||||
submitCount: integer('submit_count').default(0).notNull(),
|
||||
organizationId: uuid('organization_id'),
|
||||
submit_count: integer('submit_count').default(0).notNull(),
|
||||
organization_id: uuid('organization_id'),
|
||||
}, (table) => [
|
||||
index('selfservice_registration_flows_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_registration_flows_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
|
@ -128,17 +128,17 @@ export const selfserviceRegistrationFlows = pgTable('selfservice_registration_fl
|
|||
|
||||
export const identities = pgTable('identities', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
schemaId: varchar('schema_id', { length: 2048 }).notNull(),
|
||||
schema_id: varchar('schema_id', { length: 2048 }).notNull(),
|
||||
traits: jsonb().notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
state: varchar({ length: 255 }).default('active').notNull(),
|
||||
stateChangedAt: timestamp('state_changed_at', { mode: 'string' }),
|
||||
metadataPublic: jsonb('metadata_public'),
|
||||
metadataAdmin: jsonb('metadata_admin'),
|
||||
availableAal: varchar('available_aal', { length: 4 }),
|
||||
organizationId: uuid('organization_id'),
|
||||
state_changed_at: timestamp('state_changed_at', { mode: 'string' }),
|
||||
metadata_public: jsonb('metadata_public'),
|
||||
metadata_admin: jsonb('metadata_admin'),
|
||||
available_aal: varchar('available_aal', { length: 4 }),
|
||||
organization_id: uuid('organization_id'),
|
||||
}, (table) => [
|
||||
index('identities_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identities_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
|
@ -149,23 +149,23 @@ export const identities = pgTable('identities', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityCredentialIdentifiers = pgTable('identity_credential_identifiers', {
|
||||
export const identity_credential_identifiers = pgTable('identity_credential_identifiers', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
identifier: varchar({ length: 255 }).notNull(),
|
||||
identityCredentialId: uuid('identity_credential_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
identity_credential_id: uuid('identity_credential_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
identityCredentialTypeId: uuid('identity_credential_type_id').notNull(),
|
||||
identity_credential_type_id: uuid('identity_credential_type_id').notNull(),
|
||||
}, (table) => [
|
||||
index('identity_credential_identifiers_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
uniqueIndex('identity_credential_identifiers_identifier_nid_type_uq_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.identityCredentialTypeId.asc().nullsLast().op('uuid_ops'), table.identifier.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credential_identifiers_nid_i_ici_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.identifier.asc().nullsLast().op('text_ops'), table.identityCredentialId.asc().nullsLast().op('text_ops')),
|
||||
uniqueIndex('identity_credential_identifiers_identifier_nid_type_uq_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.identity_credential_type_id.asc().nullsLast().op('uuid_ops'), table.identifier.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credential_identifiers_nid_i_ici_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.identifier.asc().nullsLast().op('text_ops'), table.identity_credential_id.asc().nullsLast().op('text_ops')),
|
||||
index('identity_credential_identifiers_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credential_identifiers_nid_identity_credential_id_idx').using('btree', table.identityCredentialId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_credential_identifiers_nid_identity_credential_id_idx').using('btree', table.identity_credential_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityCredentialId],
|
||||
foreignColumns: [identityCredentials.id],
|
||||
columns: [table.identity_credential_id],
|
||||
foreignColumns: [identity_credentials.id],
|
||||
name: 'identity_credential_identifiers_identity_credential_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -174,31 +174,31 @@ export const identityCredentialIdentifiers = pgTable('identity_credential_identi
|
|||
name: 'identity_credential_identifiers_nid_fk_idx',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityCredentialTypeId],
|
||||
foreignColumns: [identityCredentialTypes.id],
|
||||
columns: [table.identity_credential_type_id],
|
||||
foreignColumns: [identity_credential_types.id],
|
||||
name: 'identity_credential_identifiers_type_id_fk_idx',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityVerifiableAddresses = pgTable('identity_verifiable_addresses', {
|
||||
export const identity_verifiable_addresses = pgTable('identity_verifiable_addresses', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
status: varchar({ length: 16 }).notNull(),
|
||||
via: varchar({ length: 16 }).notNull(),
|
||||
verified: boolean().notNull(),
|
||||
value: varchar({ length: 400 }).notNull(),
|
||||
verifiedAt: timestamp('verified_at', { mode: 'string' }),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
verified_at: timestamp('verified_at', { mode: 'string' }),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
}, (table) => [
|
||||
index('identity_verifiable_addresses_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verifiable_addresses_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verifiable_addresses_nid_identity_id_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verifiable_addresses_nid_identity_id_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verifiable_addresses_status_via_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.via.asc().nullsLast().op('text_ops'), table.value.asc().nullsLast().op('text_ops')),
|
||||
uniqueIndex('identity_verifiable_addresses_status_via_uq_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.via.asc().nullsLast().op('text_ops'), table.value.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_verifiable_addresses_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -209,27 +209,27 @@ export const identityVerifiableAddresses = pgTable('identity_verifiable_addresse
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const courierMessages = pgTable('courier_messages', {
|
||||
export const courier_messages = pgTable('courier_messages', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
type: integer().notNull(),
|
||||
status: integer().notNull(),
|
||||
body: text().notNull(),
|
||||
subject: varchar({ length: 255 }).notNull(),
|
||||
recipient: varchar({ length: 255 }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
templateType: varchar('template_type', { length: 255 }).default('').notNull(),
|
||||
// TODO: failed to parse database type 'bytea'
|
||||
templateData: varchar('template_data'),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
template_type: varchar('template_type', { length: 255 }).default('').notNull(),
|
||||
// todo: failed to parse database type 'bytea'
|
||||
template_data: varchar('template_data'),
|
||||
nid: uuid(),
|
||||
sendCount: integer('send_count').default(0).notNull(),
|
||||
send_count: integer('send_count').default(0).notNull(),
|
||||
channel: varchar({ length: 32 }),
|
||||
}, (table) => [
|
||||
index('courier_messages_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('courier_messages_nid_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('timestamp_ops'), table.createdAt.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_nid_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('timestamp_ops'), table.created_at.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('courier_messages_nid_recipient_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('timestamp_ops'), table.recipient.asc().nullsLast().op('text_ops'), table.createdAt.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_nid_status_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.status.asc().nullsLast().op('timestamp_ops'), table.createdAt.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_nid_recipient_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('timestamp_ops'), table.recipient.asc().nullsLast().op('text_ops'), table.created_at.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_nid_status_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.status.asc().nullsLast().op('timestamp_ops'), table.created_at.desc().nullsFirst().op('uuid_ops')),
|
||||
index('courier_messages_status_idx').using('btree', table.status.asc().nullsLast().op('int4_ops')),
|
||||
foreignKey({
|
||||
columns: [table.nid],
|
||||
|
@ -238,14 +238,14 @@ export const courierMessages = pgTable('courier_messages', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const selfserviceErrors = pgTable('selfservice_errors', {
|
||||
export const selfservice_errors = pgTable('selfservice_errors', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
errors: jsonb().notNull(),
|
||||
seenAt: timestamp('seen_at', { mode: 'string' }),
|
||||
wasSeen: boolean('was_seen').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
csrfToken: varchar('csrf_token', { length: 255 }).default('').notNull(),
|
||||
seen_at: timestamp('seen_at', { mode: 'string' }),
|
||||
was_seen: boolean('was_seen').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
csrf_token: varchar('csrf_token', { length: 255 }).default('').notNull(),
|
||||
nid: uuid(),
|
||||
}, (table) => [
|
||||
index('selfservice_errors_errors_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
|
@ -256,24 +256,24 @@ export const selfserviceErrors = pgTable('selfservice_errors', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const selfserviceVerificationFlows = pgTable('selfservice_verification_flows', {
|
||||
export const selfservice_verification_flows = pgTable('selfservice_verification_flows', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
requestUrl: text('request_url').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
csrfToken: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
request_url: text('request_url').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
csrf_token: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
type: varchar({ length: 16 }).default('browser').notNull(),
|
||||
state: varchar({ length: 255 }).default('show_form').notNull(),
|
||||
activeMethod: varchar('active_method', { length: 32 }),
|
||||
active_method: varchar('active_method', { length: 32 }),
|
||||
ui: jsonb(),
|
||||
nid: uuid(),
|
||||
submitCount: integer('submit_count').default(0).notNull(),
|
||||
oauth2LoginChallenge: text('oauth2_login_challenge'),
|
||||
sessionId: uuid('session_id'),
|
||||
identityId: uuid('identity_id'),
|
||||
authenticationMethods: json('authentication_methods'),
|
||||
submit_count: integer('submit_count').default(0).notNull(),
|
||||
oauth2login_challenge: text('oauth2_login_challenge'),
|
||||
session_id: uuid('session_id'),
|
||||
identity_id: uuid('identity_id'),
|
||||
authentication_methods: json('authentication_methods'),
|
||||
}, (table) => [
|
||||
index('selfservice_verification_flows_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_verification_flows_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
|
@ -284,26 +284,26 @@ export const selfserviceVerificationFlows = pgTable('selfservice_verification_fl
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const selfserviceSettingsFlows = pgTable('selfservice_settings_flows', {
|
||||
export const selfservice_settings_flows = pgTable('selfservice_settings_flows', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
requestUrl: text('request_url').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
activeMethod: varchar('active_method', { length: 32 }),
|
||||
request_url: text('request_url').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
active_method: varchar('active_method', { length: 32 }),
|
||||
state: varchar({ length: 255 }).default('show_form').notNull(),
|
||||
type: varchar({ length: 16 }).default('browser').notNull(),
|
||||
ui: jsonb(),
|
||||
nid: uuid(),
|
||||
internalContext: jsonb('internal_context').notNull(),
|
||||
internal_context: jsonb('internal_context').notNull(),
|
||||
}, (table) => [
|
||||
index('selfservice_settings_flows_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_settings_flows_identity_id_nid_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_settings_flows_identity_id_nid_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_settings_flows_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'selfservice_profile_management_requests_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -314,21 +314,21 @@ export const selfserviceSettingsFlows = pgTable('selfservice_settings_flows', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const continuityContainers = pgTable('continuity_containers', {
|
||||
export const continuity_containers = pgTable('continuity_containers', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
identityId: uuid('identity_id'),
|
||||
identity_id: uuid('identity_id'),
|
||||
name: varchar({ length: 255 }).notNull(),
|
||||
payload: jsonb(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
}, (table) => [
|
||||
index('continuity_containers_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('continuity_containers_identity_id_nid_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('continuity_containers_identity_id_nid_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('continuity_containers_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'continuity_containers_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -341,28 +341,28 @@ export const continuityContainers = pgTable('continuity_containers', {
|
|||
|
||||
export const sessions = pgTable('sessions', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
authenticatedAt: timestamp('authenticated_at', { mode: 'string' }).notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
authenticated_at: timestamp('authenticated_at', { mode: 'string' }).notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
token: varchar({ length: 39 }),
|
||||
active: boolean().default(false),
|
||||
nid: uuid(),
|
||||
logoutToken: varchar('logout_token', { length: 39 }),
|
||||
logout_token: varchar('logout_token', { length: 39 }),
|
||||
aal: varchar({ length: 4 }).default('aal1').notNull(),
|
||||
authenticationMethods: jsonb('authentication_methods').notNull(),
|
||||
authentication_methods: jsonb('authentication_methods').notNull(),
|
||||
}, (table) => [
|
||||
index('sessions_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('sessions_identity_id_nid_sorted_idx').using('btree', table.identityId.asc().nullsLast().op('timestamp_ops'), table.nid.asc().nullsLast().op('timestamp_ops'), table.authenticatedAt.desc().nullsFirst().op('uuid_ops')),
|
||||
uniqueIndex('sessions_logout_token_uq_idx').using('btree', table.logoutToken.asc().nullsLast().op('text_ops')),
|
||||
index('sessions_nid_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.createdAt.desc().nullsFirst().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('sessions_nid_id_identity_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.identityId.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('sessions_identity_id_nid_sorted_idx').using('btree', table.identity_id.asc().nullsLast().op('timestamp_ops'), table.nid.asc().nullsLast().op('timestamp_ops'), table.authenticated_at.desc().nullsFirst().op('uuid_ops')),
|
||||
uniqueIndex('sessions_logout_token_uq_idx').using('btree', table.logout_token.asc().nullsLast().op('text_ops')),
|
||||
index('sessions_nid_created_at_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.created_at.desc().nullsFirst().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('sessions_nid_id_identity_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.identity_id.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('sessions_token_nid_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.token.asc().nullsLast().op('text_ops')),
|
||||
uniqueIndex('sessions_token_uq_idx').using('btree', table.token.asc().nullsLast().op('text_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'sessions_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -373,22 +373,22 @@ export const sessions = pgTable('sessions', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityRecoveryAddresses = pgTable('identity_recovery_addresses', {
|
||||
export const identity_recovery_addresses = pgTable('identity_recovery_addresses', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
via: varchar({ length: 16 }).notNull(),
|
||||
value: varchar({ length: 400 }).notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
}, (table) => [
|
||||
index('identity_recovery_addresses_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_addresses_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_addresses_nid_identity_id_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_addresses_nid_identity_id_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_addresses_status_via_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.via.asc().nullsLast().op('text_ops'), table.value.asc().nullsLast().op('text_ops')),
|
||||
uniqueIndex('identity_recovery_addresses_status_via_uq_idx').using('btree', table.nid.asc().nullsLast().op('text_ops'), table.via.asc().nullsLast().op('text_ops'), table.value.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_recovery_addresses_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -399,33 +399,33 @@ export const identityRecoveryAddresses = pgTable('identity_recovery_addresses',
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityVerificationTokens = pgTable('identity_verification_tokens', {
|
||||
export const identity_verification_tokens = pgTable('identity_verification_tokens', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
token: varchar({ length: 64 }).notNull(),
|
||||
used: boolean().default(false).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).notNull(),
|
||||
identityVerifiableAddressId: uuid('identity_verifiable_address_id').notNull(),
|
||||
selfserviceVerificationFlowId: uuid('selfservice_verification_flow_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).notNull(),
|
||||
identity_verifiable_address_id: uuid('identity_verifiable_address_id').notNull(),
|
||||
selfservice_verification_flow_id: uuid('selfservice_verification_flow_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid(),
|
||||
}, (table) => [
|
||||
index('identity_verification_tokens_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_token_nid_used_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.token.asc().nullsLast().op('bool_ops'), table.used.asc().nullsLast().op('text_ops'), table.selfserviceVerificationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_token_nid_used_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.token.asc().nullsLast().op('bool_ops'), table.used.asc().nullsLast().op('text_ops'), table.selfservice_verification_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
uniqueIndex('identity_verification_tokens_token_uq_idx').using('btree', table.token.asc().nullsLast().op('text_ops')),
|
||||
index('identity_verification_tokens_verifiable_address_id_idx').using('btree', table.identityVerifiableAddressId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_verification_flow_id_idx').using('btree', table.selfserviceVerificationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_verifiable_address_id_idx').using('btree', table.identity_verifiable_address_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_tokens_verification_flow_id_idx').using('btree', table.selfservice_verification_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityVerifiableAddressId],
|
||||
foreignColumns: [identityVerifiableAddresses.id],
|
||||
columns: [table.identity_verifiable_address_id],
|
||||
foreignColumns: [identity_verifiable_addresses.id],
|
||||
name: 'identity_verification_tokens_identity_verifiable_address_i_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceVerificationFlowId],
|
||||
foreignColumns: [selfserviceVerificationFlows.id],
|
||||
columns: [table.selfservice_verification_flow_id],
|
||||
foreignColumns: [selfservice_verification_flows.id],
|
||||
name: 'identity_verification_tokens_selfservice_verification_flow_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -435,28 +435,28 @@ export const identityVerificationTokens = pgTable('identity_verification_tokens'
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const selfserviceRecoveryFlows = pgTable('selfservice_recovery_flows', {
|
||||
export const selfservice_recovery_flows = pgTable('selfservice_recovery_flows', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
requestUrl: text('request_url').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
activeMethod: varchar('active_method', { length: 32 }),
|
||||
csrfToken: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
request_url: text('request_url').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).notNull(),
|
||||
active_method: varchar('active_method', { length: 32 }),
|
||||
csrf_token: varchar('csrf_token', { length: 255 }).notNull(),
|
||||
state: varchar({ length: 32 }).notNull(),
|
||||
recoveredIdentityId: uuid('recovered_identity_id'),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
recovered_identity_id: uuid('recovered_identity_id'),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
type: varchar({ length: 16 }).default('browser').notNull(),
|
||||
ui: jsonb(),
|
||||
nid: uuid(),
|
||||
submitCount: integer('submit_count').default(0).notNull(),
|
||||
skipCsrfCheck: boolean('skip_csrf_check').default(false).notNull(),
|
||||
submit_count: integer('submit_count').default(0).notNull(),
|
||||
skip_csrf_check: boolean('skip_csrf_check').default(false).notNull(),
|
||||
}, (table) => [
|
||||
index('selfservice_recovery_flows_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_recovery_flows_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_recovery_flows_recovered_identity_id_nid_idx').using('btree', table.recoveredIdentityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('selfservice_recovery_flows_recovered_identity_id_nid_idx').using('btree', table.recovered_identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.recoveredIdentityId],
|
||||
columns: [table.recovered_identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'selfservice_recovery_requests_recovered_identity_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -467,31 +467,31 @@ export const selfserviceRecoveryFlows = pgTable('selfservice_recovery_flows', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityRecoveryTokens = pgTable('identity_recovery_tokens', {
|
||||
export const identity_recovery_tokens = pgTable('identity_recovery_tokens', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
token: varchar({ length: 64 }).notNull(),
|
||||
used: boolean().default(false).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
identityRecoveryAddressId: uuid('identity_recovery_address_id'),
|
||||
selfserviceRecoveryFlowId: uuid('selfservice_recovery_flow_id'),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
identity_recovery_address_id: uuid('identity_recovery_address_id'),
|
||||
selfservice_recovery_flow_id: uuid('selfservice_recovery_flow_id'),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
nid: uuid(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
tokenType: integer('token_type').default(0).notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
token_type: integer('token_type').default(0).notNull(),
|
||||
}, (table) => [
|
||||
uniqueIndex('identity_recovery_addresses_code_uq_idx').using('btree', table.token.asc().nullsLast().op('text_ops')),
|
||||
index('identity_recovery_tokens_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_identity_id_nid_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_identity_recovery_address_id_idx').using('btree', table.identityRecoveryAddressId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_identity_id_nid_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_identity_recovery_address_id_idx').using('btree', table.identity_recovery_address_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_nid_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_selfservice_recovery_flow_id_idx').using('btree', table.selfserviceRecoveryFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_selfservice_recovery_flow_id_idx').using('btree', table.selfservice_recovery_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_tokens_token_nid_used_idx').using('btree', table.nid.asc().nullsLast().op('bool_ops'), table.token.asc().nullsLast().op('text_ops'), table.used.asc().nullsLast().op('bool_ops')),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceRecoveryFlowId],
|
||||
foreignColumns: [selfserviceRecoveryFlows.id],
|
||||
columns: [table.selfservice_recovery_flow_id],
|
||||
foreignColumns: [selfservice_recovery_flows.id],
|
||||
name: 'identity_recovery_tokens_selfservice_recovery_request_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -500,50 +500,51 @@ export const identityRecoveryTokens = pgTable('identity_recovery_tokens', {
|
|||
name: 'identity_recovery_tokens_nid_fk_idx',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityRecoveryAddressId],
|
||||
foreignColumns: [identityRecoveryAddresses.id],
|
||||
columns: [table.identity_recovery_address_id],
|
||||
foreignColumns: [identity_recovery_addresses.id],
|
||||
name: 'identity_recovery_tokens_identity_recovery_address_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_recovery_tokens_identity_id_fk_idx',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
check('identity_recovery_tokens_token_type_ck', sql`(token_type = 1)
|
||||
OR (token_type = 2)`),
|
||||
or
|
||||
(token_type = 2)`),
|
||||
]);
|
||||
|
||||
export const identityRecoveryCodes = pgTable('identity_recovery_codes', {
|
||||
export const identity_recovery_codes = pgTable('identity_recovery_codes', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
code: varchar({ length: 64 }).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
identityRecoveryAddressId: uuid('identity_recovery_address_id'),
|
||||
codeType: integer('code_type').notNull(),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfserviceRecoveryFlowId: uuid('selfservice_recovery_flow_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
identity_recovery_address_id: uuid('identity_recovery_address_id'),
|
||||
code_type: integer('code_type').notNull(),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfservice_recovery_flow_id: uuid('selfservice_recovery_flow_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid().notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
}, (table) => [
|
||||
index('identity_recovery_codes_flow_id_idx').using('btree', table.selfserviceRecoveryFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_flow_id_idx').using('btree', table.selfservice_recovery_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_identity_id_nid_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_identity_recovery_address_id_nid_idx').using('btree', table.identityRecoveryAddressId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfserviceRecoveryFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_identity_id_nid_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_identity_recovery_address_id_nid_idx').using('btree', table.identity_recovery_address_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_recovery_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfservice_recovery_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityRecoveryAddressId],
|
||||
foreignColumns: [identityRecoveryAddresses.id],
|
||||
columns: [table.identity_recovery_address_id],
|
||||
foreignColumns: [identity_recovery_addresses.id],
|
||||
name: 'identity_recovery_codes_identity_recovery_addresses_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceRecoveryFlowId],
|
||||
foreignColumns: [selfserviceRecoveryFlows.id],
|
||||
columns: [table.selfservice_recovery_flow_id],
|
||||
foreignColumns: [selfservice_recovery_flows.id],
|
||||
name: 'identity_recovery_codes_selfservice_recovery_flows_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_recovery_codes_identity_id_fk',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
|
@ -554,20 +555,20 @@ export const identityRecoveryCodes = pgTable('identity_recovery_codes', {
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const sessionDevices = pgTable('session_devices', {
|
||||
export const session_devices = pgTable('session_devices', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
ipAddress: varchar('ip_address', { length: 50 }).default(''),
|
||||
userAgent: varchar('user_agent', { length: 512 }).default(''),
|
||||
ip_address: varchar('ip_address', { length: 50 }).default(''),
|
||||
user_agent: varchar('user_agent', { length: 512 }).default(''),
|
||||
location: varchar({ length: 512 }).default(''),
|
||||
nid: uuid().notNull(),
|
||||
sessionId: uuid('session_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
session_id: uuid('session_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
}, (table) => [
|
||||
index('session_devices_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('session_devices_session_id_nid_idx').using('btree', table.sessionId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('session_devices_session_id_nid_idx').using('btree', table.session_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.sessionId],
|
||||
columns: [table.session_id],
|
||||
foreignColumns: [sessions.id],
|
||||
name: 'session_metadata_sessions_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
|
@ -576,33 +577,33 @@ export const sessionDevices = pgTable('session_devices', {
|
|||
foreignColumns: [networks.id],
|
||||
name: 'session_metadata_nid_fk',
|
||||
}).onDelete('cascade'),
|
||||
unique('unique_session_device').on(table.ipAddress, table.userAgent, table.nid, table.sessionId),
|
||||
unique('unique_session_device').on(table.ip_address, table.user_agent, table.nid, table.session_id),
|
||||
]);
|
||||
|
||||
export const identityVerificationCodes = pgTable('identity_verification_codes', {
|
||||
export const identity_verification_codes = pgTable('identity_verification_codes', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
codeHmac: varchar('code_hmac', { length: 64 }).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
identityVerifiableAddressId: uuid('identity_verifiable_address_id'),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfserviceVerificationFlowId: uuid('selfservice_verification_flow_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
code_hmac: varchar('code_hmac', { length: 64 }).notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
identity_verifiable_address_id: uuid('identity_verifiable_address_id'),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfservice_verification_flow_id: uuid('selfservice_verification_flow_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
nid: uuid().notNull(),
|
||||
}, (table) => [
|
||||
index('identity_verification_codes_flow_id_idx').using('btree', table.selfserviceVerificationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_flow_id_idx').using('btree', table.selfservice_verification_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfserviceVerificationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_verifiable_address_nid_idx').using('btree', table.identityVerifiableAddressId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfservice_verification_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_verification_codes_verifiable_address_nid_idx').using('btree', table.identity_verifiable_address_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.identityVerifiableAddressId],
|
||||
foreignColumns: [identityVerifiableAddresses.id],
|
||||
columns: [table.identity_verifiable_address_id],
|
||||
foreignColumns: [identity_verifiable_addresses.id],
|
||||
name: 'identity_verification_codes_identity_verifiable_addresses_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceVerificationFlowId],
|
||||
foreignColumns: [selfserviceVerificationFlows.id],
|
||||
columns: [table.selfservice_verification_flow_id],
|
||||
foreignColumns: [selfservice_verification_flows.id],
|
||||
name: 'identity_verification_codes_selfservice_verification_flows_id_f',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -612,20 +613,20 @@ export const identityVerificationCodes = pgTable('identity_verification_codes',
|
|||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const courierMessageDispatches = pgTable('courier_message_dispatches', {
|
||||
export const courier_message_dispatches = pgTable('courier_message_dispatches', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
messageId: uuid('message_id').notNull(),
|
||||
message_id: uuid('message_id').notNull(),
|
||||
status: varchar({ length: 7 }).notNull(),
|
||||
error: json(),
|
||||
nid: uuid().notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
}, (table) => [
|
||||
index('courier_message_dispatches_message_id_idx').using('btree', table.messageId.asc().nullsLast().op('timestamp_ops'), table.createdAt.desc().nullsFirst().op('timestamp_ops')),
|
||||
index('courier_message_dispatches_message_id_idx').using('btree', table.message_id.asc().nullsLast().op('timestamp_ops'), table.created_at.desc().nullsFirst().op('timestamp_ops')),
|
||||
index('courier_message_dispatches_nid_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.messageId],
|
||||
foreignColumns: [courierMessages.id],
|
||||
columns: [table.message_id],
|
||||
foreignColumns: [courier_messages.id],
|
||||
name: 'courier_message_dispatches_message_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -635,41 +636,41 @@ export const courierMessageDispatches = pgTable('courier_message_dispatches', {
|
|||
}).onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const sessionTokenExchanges = pgTable('session_token_exchanges', {
|
||||
export const session_token_exchanges = pgTable('session_token_exchanges', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
nid: uuid().notNull(),
|
||||
flowId: uuid('flow_id').notNull(),
|
||||
sessionId: uuid('session_id'),
|
||||
initCode: varchar('init_code', { length: 64 }).notNull(),
|
||||
returnToCode: varchar('return_to_code', { length: 64 }).notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
flow_id: uuid('flow_id').notNull(),
|
||||
session_id: uuid('session_id'),
|
||||
init_code: varchar('init_code', { length: 64 }).notNull(),
|
||||
return_to_code: varchar('return_to_code', { length: 64 }).notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).notNull(),
|
||||
}, (table) => [
|
||||
index('session_token_exchanges_nid_code_idx').using('btree', table.initCode.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('text_ops')),
|
||||
index('session_token_exchanges_nid_flow_id_idx').using('btree', table.flowId.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('session_token_exchanges_nid_code_idx').using('btree', table.init_code.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('text_ops')),
|
||||
index('session_token_exchanges_nid_flow_id_idx').using('btree', table.flow_id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
]);
|
||||
|
||||
export const identityLoginCodes = pgTable('identity_login_codes', {
|
||||
export const identity_login_codes = pgTable('identity_login_codes', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
code: varchar({ length: 64 }).notNull(),
|
||||
address: varchar({ length: 255 }).notNull(),
|
||||
addressType: char('address_type', { length: 36 }).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfserviceLoginFlowId: uuid('selfservice_login_flow_id').notNull(),
|
||||
identityId: uuid('identity_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
address_type: char('address_type', { length: 36 }).notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfservice_login_flow_id: uuid('selfservice_login_flow_id').notNull(),
|
||||
identity_id: uuid('identity_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
nid: uuid().notNull(),
|
||||
}, (table) => [
|
||||
index('identity_login_codes_flow_id_idx').using('btree', table.selfserviceLoginFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_flow_id_idx').using('btree', table.selfservice_login_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_identity_id_idx').using('btree', table.identityId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfserviceLoginFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_identity_id_idx').using('btree', table.identity_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_login_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfservice_login_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceLoginFlowId],
|
||||
foreignColumns: [selfserviceLoginFlows.id],
|
||||
columns: [table.selfservice_login_flow_id],
|
||||
foreignColumns: [selfservice_login_flows.id],
|
||||
name: 'identity_login_codes_selfservice_login_flows_id_fk',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
@ -678,31 +679,31 @@ export const identityLoginCodes = pgTable('identity_login_codes', {
|
|||
name: 'identity_login_codes_networks_id_fk',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
foreignKey({
|
||||
columns: [table.identityId],
|
||||
columns: [table.identity_id],
|
||||
foreignColumns: [identities.id],
|
||||
name: 'identity_login_codes_identity_id_fk',
|
||||
}).onUpdate('restrict').onDelete('cascade'),
|
||||
]);
|
||||
|
||||
export const identityRegistrationCodes = pgTable('identity_registration_codes', {
|
||||
export const identity_registration_codes = pgTable('identity_registration_codes', {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
code: varchar({ length: 64 }).notNull(),
|
||||
address: varchar({ length: 255 }).notNull(),
|
||||
addressType: char('address_type', { length: 36 }).notNull(),
|
||||
usedAt: timestamp('used_at', { mode: 'string' }),
|
||||
expiresAt: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issuedAt: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfserviceRegistrationFlowId: uuid('selfservice_registration_flow_id').notNull(),
|
||||
createdAt: timestamp('created_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
updatedAt: timestamp('updated_at', { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
address_type: char('address_type', { length: 36 }).notNull(),
|
||||
used_at: timestamp('used_at', { mode: 'string' }),
|
||||
expires_at: timestamp('expires_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
issued_at: timestamp('issued_at', { mode: 'string' }).default('2000-01-01 00:00:00').notNull(),
|
||||
selfservice_registration_flow_id: uuid('selfservice_registration_flow_id').notNull(),
|
||||
created_at: timestamp('created_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
updated_at: timestamp('updated_at', { mode: 'string' }).default(sql`current_timestamp`).notNull(),
|
||||
nid: uuid().notNull(),
|
||||
}, (table) => [
|
||||
index('identity_registration_codes_flow_id_idx').using('btree', table.selfserviceRegistrationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_registration_codes_flow_id_idx').using('btree', table.selfservice_registration_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_registration_codes_id_nid_idx').using('btree', table.id.asc().nullsLast().op('uuid_ops'), table.nid.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_registration_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfserviceRegistrationFlowId.asc().nullsLast().op('uuid_ops')),
|
||||
index('identity_registration_codes_nid_flow_id_idx').using('btree', table.nid.asc().nullsLast().op('uuid_ops'), table.selfservice_registration_flow_id.asc().nullsLast().op('uuid_ops')),
|
||||
foreignKey({
|
||||
columns: [table.selfserviceRegistrationFlowId],
|
||||
foreignColumns: [selfserviceRegistrationFlows.id],
|
||||
columns: [table.selfservice_registration_flow_id],
|
||||
foreignColumns: [selfservice_registration_flows.id],
|
||||
name: 'identity_registration_codes_selfservice_registration_flows_id_f',
|
||||
}).onDelete('cascade'),
|
||||
foreignKey({
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
VerifiableIdentityAddress,
|
||||
} from '@ory/client';
|
||||
import { getDB } from '@/db';
|
||||
import { identities, identityRecoveryAddresses, identityVerifiableAddresses } from '@/db/schema';
|
||||
import { identities, identity_recovery_addresses, identity_verifiable_addresses } from '@/db/schema';
|
||||
import { eq, ilike, or, sql } from 'drizzle-orm';
|
||||
|
||||
interface QueryIdentitiesProps {
|
||||
|
@ -31,14 +31,14 @@ export async function queryIdentities({ page, pageSize, query }: QueryIdentities
|
|||
const db = await getDB();
|
||||
const result = await db.select()
|
||||
.from(identities)
|
||||
.leftJoin(identityVerifiableAddresses, eq(identities.id, identityVerifiableAddresses.identityId))
|
||||
.leftJoin(identityRecoveryAddresses, eq(identities.id, identityRecoveryAddresses.identityId))
|
||||
.leftJoin(identity_verifiable_addresses, eq(identities.id, identity_verifiable_addresses.identity_id))
|
||||
.leftJoin(identity_recovery_addresses, eq(identities.id, identity_recovery_addresses.identity_id))
|
||||
.where(or(
|
||||
sql`${identities.id}::text ILIKE
|
||||
${`%${query}%`}`,
|
||||
sql`${identities.traits}::text ILIKE
|
||||
${`%${query}%`}`,
|
||||
ilike(identityVerifiableAddresses.value, `%${query}%`),
|
||||
ilike(identity_verifiable_addresses.value, `%${query}%`),
|
||||
))
|
||||
.orderBy(identities.id)
|
||||
.limit(pageSize)
|
||||
|
@ -47,14 +47,14 @@ export async function queryIdentities({ page, pageSize, query }: QueryIdentities
|
|||
const resultCount = await db.$count(
|
||||
db.select()
|
||||
.from(identities)
|
||||
.leftJoin(identityVerifiableAddresses, eq(identities.id, identityVerifiableAddresses.identityId))
|
||||
.leftJoin(identityRecoveryAddresses, eq(identities.id, identityRecoveryAddresses.identityId))
|
||||
.leftJoin(identity_verifiable_addresses, eq(identities.id, identity_verifiable_addresses.identity_id))
|
||||
.leftJoin(identity_recovery_addresses, eq(identities.id, identity_recovery_addresses.identity_id))
|
||||
.where(or(
|
||||
sql`${identities.id}::text ILIKE
|
||||
${`%${query}%`}`,
|
||||
sql`${identities.traits}::text ILIKE
|
||||
${`%${query}%`}`,
|
||||
ilike(identityVerifiableAddresses.value, `%${query}%`),
|
||||
ilike(identity_verifiable_addresses.value, `%${query}%`),
|
||||
))
|
||||
.as('subquery'),
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue