import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import type AppFile from "./AppFile.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import type { AppFileVersion } from "./AppFile.js"; import { RelateToOne } from "@entity-access/entity-access/dist/decorators/Relate.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import type AppTempFile from "./AppTempFile.js"; @Table("FileContents") @Index({ name: "IX_FileContents_ContentHash", columns: [{ name: (x) => x.contentHash, descending: false }] }) @Index({ name: "IX_FileContents_Not_Indexed", columns: [{ name: (x) => x.fileContentID, descending: false }], filter: (x) => x.textDocumentID === null }) @Index({ name: "IX_FileContents_Deleted", columns: [{ name: (x) => x.fileContentID, descending: false }], filter: (x) => x.deleted === true }) @Index({ name: "IX_FileContents_Dirty", columns: [{ name: (x) => x.dateCreated, descending: false }], filter: (x) => x.cloudPath === null }) export default class FileContent { @Column({ key: true, generated: "identity", dataType: "BigInt" }) public fileContentID: number; @Column({ dataType: "AsciiChar", length: 200}) public contentHash: string; /** * Where exactly this is stored... */ @Column({ dataType: "Char", length: 450, nullable: true}) public cloudPath: string; @Column({ dataType: "Char", length: 200}) public contentType: string; @Column({ dataType: "BigInt"}) public contentSize: number; @Column({ dataType: "Char", length: 10, nullable: true }) public compression: string; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) public dateCreated: DateTime; @Column({ dataType: "BigInt", nullable: true}) // @RelateToOne({ // type: () => TextDocument, // property: (x) => x.textDocument, // inverseProperty: (x) => x.fileContent, // }) public textDocumentID: number; /** * This will be set whenever AppFile is deleted. * A cleanup workflow will check for duplicates and delete this file content. * If file has any children, this will be set back to false. */ @Column({ default: () => false }) public deleted: boolean; public appFiles: AppFile[]; public versions: AppFileVersion[]; public textDocument: TextDocument; tempFiles: AppTempFile[]; } @Table("TextDocuments") export class TextDocument { @Column({ dataType: "BigInt", key: true }) @RelateToOne(FileContent, { property: (x) => x.fileContent, inverseProperty: (x) => x.textDocument, foreignKeyConstraint: { name: "FC_TextDocuments_PK", onDelete: "cascade" } }) public textDocumentID: number; @Column({ dataType: "Char" }) public searchable: string; public fileContent: FileContent; }