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
@@ -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 { CollectionPlacesRepository } from '../repositories/CollectionPlaces.repository';
import { DbTimestampType } from '../types';
import { Categories } from './Categories.entity';
import { CollectionLabels } from './CollectionLabels.entity';
import { CollectionPlaceRatings } from './CollectionPlaceRatings.entity';
@@ -7,71 +9,77 @@ import { Tags } from './Tags.entity';
import { Users } from './Users.entity';
export class CollectionPlaces {
id?: number | null;
id!: number & Opt;
collection!: Ref<Collections>;
collection_id!: number;
owner!: Ref<Users>;
savedBy?: Ref<Users> | null;
owner_id!: number;
saved_by?: number | null;
name!: string;
description?: string | null;
lat?: unknown | null;
lng?: unknown | null;
lat?: number | null;
lng?: number | null;
address?: string | null;
category?: Ref<Categories> | null;
price?: unknown | null;
category_id?: number | null;
price?: number | null;
currency?: string | null;
notes?: string | null;
imageUrl?: string | null;
googlePlaceId?: string | null;
googleFtid?: string | null;
osmId?: string | null;
image_url?: string | null;
google_place_id?: string | null;
google_ftid?: string | null;
osm_id?: string | null;
website?: string | null;
phone?: string | null;
status: string & Opt = 'idea';
sourceTripId?: number | null;
sourcePlaceId?: number | null;
source_trip_id?: number | null;
source_place_id?: number | null;
links?: string | null;
sortOrder?: number | null = 0;
createdAt?: Date | null;
updatedAt?: Date | null;
collectionPlaceLabels = new Collection<CollectionLabels>(this);
collectionPlaceTags = new Collection<Tags>(this);
collectionPlaceRatingsCollection = new Collection<CollectionPlaceRatings>(this);
sort_order?: number | null = 0;
created_at?: string | null;
updated_at?: string | null;
savedByRef?: Ref<Users> | null;
collection_place_labels = new Collection<CollectionLabels>(this);
collection_place_tags = new Collection<Tags>(this);
collection_place_ratings_collection = new Collection<CollectionPlaceRatings>(this);
}
export class CollectionPlacesRepository extends EntityRepository<CollectionPlaces> {}
export const CollectionPlacesSchema = defineEntity({
class: CollectionPlaces,
repository: () => CollectionPlacesRepository,
properties: {
id: p.integer().primary().autoincrement(),
collection: () => p.manyToOne(Collections).ref().deleteRule('cascade').index('idx_collection_places_collection'),
owner: () => p.manyToOne(Users).ref().deleteRule('cascade'),
savedBy: () => p.manyToOne(Users).ref().name('saved_by').nullable(),
id: p.integer().primary(),
collection: () => p.manyToOne(Collections).ref().deleteRule('cascade').hidden().index('idx_collection_places_collection'),
collection_id: p.integer().persist(false).index('idx_collection_places_collection'),
owner: () => p.manyToOne(Users).ref().deleteRule('cascade').hidden(),
owner_id: p.integer().persist(false),
saved_by: p.integer().nullable().persist(false),
name: p.text(),
description: p.text().nullable(),
lat: p.double().nullable(),
lng: p.double().nullable(),
address: p.text().nullable(),
category: () => p.manyToOne(Categories).ref().nullable(),
category: () => p.manyToOne(Categories).ref().nullable().hidden(),
category_id: p.integer().nullable().persist(false),
price: p.double().nullable(),
currency: p.text().nullable(),
notes: p.text().nullable(),
imageUrl: p.text().nullable(),
googlePlaceId: p.text().nullable(),
googleFtid: p.text().nullable(),
osmId: p.text().nullable(),
image_url: p.text().nullable(),
google_place_id: p.text().nullable(),
google_ftid: p.text().nullable(),
osm_id: p.text().nullable(),
website: p.text().nullable(),
phone: p.text().nullable(),
status: p.text(),
sourceTripId: p.integer().nullable(),
sourcePlaceId: p.integer().nullable(),
status: p.text().default('idea'),
source_trip_id: p.integer().nullable(),
source_place_id: p.integer().nullable(),
links: p.text().nullable(),
sortOrder: p.integer().nullable(),
createdAt: p.datetime().nullable().onCreate(() => new Date()),
updatedAt: p.datetime().nullable().onCreate(() => new Date()),
collectionPlaceLabels: () => p.manyToMany(CollectionLabels).pivotTable('collection_place_labels').joinColumn('collection_place_id').inverseJoinColumn('label_id'),
collectionPlaceTags: () => p.manyToMany(Tags).pivotTable('collection_place_tags').joinColumn('collection_place_id').inverseJoinColumn('tag_id'),
collectionPlaceRatingsCollection: () => p.oneToMany(CollectionPlaceRatings).mappedBy('collectionPlace'),
sort_order: p.integer().nullable(),
created_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
updated_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
savedByRef: () => p.manyToOne(Users).ref().joinColumn('saved_by').nullable().hidden(),
collection_place_labels: () => p.manyToMany(CollectionLabels).pivotTable('collection_place_labels').joinColumn('collection_place_id').inverseJoinColumn('label_id').hidden(),
collection_place_tags: () => p.manyToMany(Tags).pivotTable('collection_place_tags').joinColumn('collection_place_id').inverseJoinColumn('tag_id').hidden(),
collection_place_ratings_collection: () => p.oneToMany(CollectionPlaceRatings).mappedBy('collectionPlace').hidden(),
},
});