feat(index): Index module foundation (#9095)

**What**
Index module foundation

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Adrien de PerettiandCarlos R. L. Rodrigues authored and GitHub committed 2024-09-18 19:04:04 +00:00
1 parent 3cfcd075ae
commit 58167b5dfa
53 files changed
+4796 -1201

No files matched your search

@@ -0,0 +1,45 @@
import {
Cascade,
Collection,
Entity,
Index,
ManyToMany,
OptionalProps,
PrimaryKey,
PrimaryKeyType,
Property,
} from "@mikro-orm/core"
import { IndexRelation } from "./index-relation"
type OptionalRelations = "parents"
@Entity({
tableName: "index_data",
})
export class IndexData {
[OptionalProps]: OptionalRelations
@PrimaryKey({ columnType: "text" })
@Index({ name: "IDX_index_data_id" })
id!: string
@PrimaryKey({ columnType: "text" })
@Index({ name: "IDX_index_data_name" })
name: string;
[PrimaryKeyType]?: [string, string]
@Index({ name: "IDX_index_data_gin", type: "GIN" })
@Property({ columnType: "jsonb", default: "{}" })
data: Record<string, unknown>
@ManyToMany({
owner: true,
entity: () => IndexData,
pivotEntity: () => IndexRelation,
cascade: [Cascade.REMOVE],
inverseJoinColumns: ["parent_id", "parent_name"],
joinColumns: ["child_id", "child_name"],
})
parents = new Collection<IndexData>(this)
}
@@ -0,0 +1,64 @@
import {
Entity,
Index,
ManyToOne,
OptionalProps,
PrimaryKey,
Property,
Ref,
} from "@mikro-orm/core"
import { IndexData } from "./index-data"
type OptionalRelations =
| "parent"
| "child"
| "parent_id"
| "child_id"
| "parent_name"
| "child_name"
@Entity({
tableName: "index_relation",
})
@Index({
name: "IDX_index_relation_child_id",
properties: ["child_id"],
})
export class IndexRelation {
[OptionalProps]: OptionalRelations
@PrimaryKey({ columnType: "integer", autoincrement: true })
id!: string
// if added as PK, BeforeCreate value isn't set
@Property({
columnType: "text",
})
pivot: string
@Property({ columnType: "text" })
parent_id?: string
@Property({ columnType: "text" })
parent_name?: string
@Property({ columnType: "text" })
child_id?: string
@Property({ columnType: "text" })
child_name?: string
@ManyToOne({
entity: () => IndexData,
onDelete: "cascade",
persist: false,
})
parent?: Ref<IndexData>
@ManyToOne({
entity: () => IndexData,
onDelete: "cascade",
persist: false,
})
child?: Ref<IndexData>
}
@@ -0,0 +1,2 @@
export { IndexData } from "./index-data"
export { IndexRelation } from "./index-relation"