mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +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
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { type Opt, type Ref, defineEntity, p } from '@mikro-orm/core';
|
|
import { VacayEntriesRepository } from '../repositories/VacayEntries.repository';
|
|
import { Users } from './Users.entity';
|
|
import { VacayPlans } from './VacayPlans.entity';
|
|
|
|
export class VacayEntries {
|
|
id!: number & Opt;
|
|
plan!: Ref<VacayPlans>;
|
|
plan_id!: number;
|
|
user!: Ref<Users>;
|
|
user_id!: number;
|
|
date!: string;
|
|
note?: string | null = '';
|
|
fraction!: number & Opt;
|
|
kind: string & Opt = 'vacation';
|
|
}
|
|
|
|
export const VacayEntriesSchema = defineEntity({
|
|
class: VacayEntries,
|
|
repository: () => VacayEntriesRepository,
|
|
uniques: [{ properties: ['user_id', 'plan_id', 'date'] }],
|
|
properties: {
|
|
id: p.integer().primary(),
|
|
plan: () => p.manyToOne(VacayPlans).ref().deleteRule('cascade').hidden(),
|
|
plan_id: p.integer().persist(false),
|
|
user: () => p.manyToOne(Users).ref().deleteRule('cascade').hidden(),
|
|
user_id: p.integer().persist(false),
|
|
date: p.text(),
|
|
note: p.text().nullable(),
|
|
fraction: p.double().defaultRaw(`1`),
|
|
kind: p.text().default('vacation'),
|
|
},
|
|
});
|