mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
310a3b0ad3
SqliteSchemaHelper.getIndexes() drops every unnamed sqlite_autoindex_ entry before entity-generator ever sees it, so a table-level UNIQUE(...) constraint with no separate named CREATE UNIQUE INDEX (settings' UNIQUE(user_id, key) among ~40 others) never reached the generated entity's uniques: metadata. Adds a general RULE9_addImplicitUniqueConstraints (skips a column set identical to the table's own primary key — AppSettings.key/Addons.id noise) fed by a PRAGMA index_list/index_info scan, and regenerates every entity.
34 lines
952 B
TypeScript
34 lines
952 B
TypeScript
import { type Opt, defineEntity, p } from '@mikro-orm/core';
|
|
import { PluginEntityMetadataRepository } from '../repositories/PluginEntityMetadata.repository';
|
|
|
|
export class PluginEntityMetadata {
|
|
id!: number & Opt;
|
|
plugin_id!: string;
|
|
entity_type!: string;
|
|
entity_id!: number;
|
|
key!: string;
|
|
value?: string | null;
|
|
updated_at!: string & Opt;
|
|
}
|
|
|
|
export const PluginEntityMetadataSchema = defineEntity({
|
|
class: PluginEntityMetadata,
|
|
repository: () => PluginEntityMetadataRepository,
|
|
indexes: [
|
|
{
|
|
name: 'idx_plugin_meta_entity',
|
|
properties: ['plugin_id', 'entity_type', 'entity_id'],
|
|
},
|
|
],
|
|
uniques: [{ properties: ['plugin_id', 'entity_type', 'entity_id', 'key'] }],
|
|
properties: {
|
|
id: p.integer().primary(),
|
|
plugin_id: p.text(),
|
|
entity_type: p.text(),
|
|
entity_id: p.integer(),
|
|
key: p.text(),
|
|
value: p.text().nullable(),
|
|
updated_at: p.text().defaultRaw(`(datetime('now'))`),
|
|
},
|
|
});
|