refactor(db): every entity in the snake_case shape; document-sync entities added; one repository per entity

This commit is contained in:
jubnl
2026-09-22 11:01:36 +02:00
parent 7534c2f903
commit 60d6e1fcd1
249 changed files with 3326 additions and 2114 deletions
+26 -24
View File
@@ -1,4 +1,6 @@
import { Collection, type Opt, type Ref, defineEntity, p, EntityRepository } from '@mikro-orm/core';
import { Collection, type Opt, type Ref, defineEntity, p } from '@mikro-orm/core';
import { OauthClientsRepository } from '../repositories/OauthClients.repository';
import { DbTimestampType } from '../types';
import { OauthConsents } from './OauthConsents.entity';
import { OauthTokens } from './OauthTokens.entity';
import { Users } from './Users.entity';
@@ -6,37 +8,37 @@ import { Users } from './Users.entity';
export class OauthClients {
id?: string | null;
user?: Ref<Users> | null;
user_id?: number | null;
name!: string;
clientId!: string;
clientSecretHash!: string;
redirectUris: string & Opt = '[]';
allowedScopes: string & Opt = '[]';
createdAt?: Date | null;
isPublic: number & Opt = 0;
createdVia: string & Opt = 'settings_ui';
allowsClientCredentials: number & Opt = 0;
oauthConsentsCollection = new Collection<OauthConsents>(this);
oauthTokensCollection = new Collection<OauthTokens>(this);
client_id!: string;
client_secret_hash!: string;
redirect_uris: string & Opt = '[]';
allowed_scopes: string & Opt = '[]';
created_at?: string | null;
is_public: number & Opt = 0;
created_via: string & Opt = 'settings_ui';
allows_client_credentials: number & Opt = 0;
oauth_consents_collection = new Collection<OauthConsents>(this);
oauth_tokens_collection = new Collection<OauthTokens>(this);
}
export class OauthClientsRepository extends EntityRepository<OauthClients> {}
export const OauthClientsSchema = defineEntity({
class: OauthClients,
repository: () => OauthClientsRepository,
properties: {
id: p.text().primary().nullable(),
user: () => p.manyToOne(Users).ref().deleteRule('cascade').nullable().index('idx_oauth_clients_user'),
user: () => p.manyToOne(Users).ref().deleteRule('cascade').nullable().hidden().index('idx_oauth_clients_user'),
user_id: p.integer().nullable().persist(false).index('idx_oauth_clients_user'),
name: p.text(),
clientId: p.text().unique('idx_oauth_clients_client_id'),
clientSecretHash: p.text(),
redirectUris: p.text(),
allowedScopes: p.text(),
createdAt: p.datetime().nullable().onCreate(() => new Date()),
isPublic: p.integer(),
createdVia: p.text(),
allowsClientCredentials: p.integer(),
oauthConsentsCollection: () => p.oneToMany(OauthConsents).mappedBy('client'),
oauthTokensCollection: () => p.oneToMany(OauthTokens).mappedBy('client'),
client_id: p.text().unique('idx_oauth_clients_client_id'),
client_secret_hash: p.text(),
redirect_uris: p.text().default('[]'),
allowed_scopes: p.text().default('[]'),
created_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
is_public: p.integer().default(0),
created_via: p.text().default('settings_ui'),
allows_client_credentials: p.integer().default(0),
oauth_consents_collection: () => p.oneToMany(OauthConsents).mappedBy('client').hidden(),
oauth_tokens_collection: () => p.oneToMany(OauthTokens).mappedBy('client').hidden(),
},
});