feat: rename schema (#19891)

This commit is contained in:
Jason Rasmussen
2025-07-14 10:13:06 -04:00
committed by GitHub
parent 33c29e4305
commit c699df002a
103 changed files with 4378 additions and 3224 deletions

View File

@@ -16,14 +16,14 @@ export class MemoryRepository implements IBulkAsset {
async cleanup() {
await this.db
.deleteFrom('memories_assets_assets')
.using('assets')
.whereRef('memories_assets_assets.assetsId', '=', 'assets.id')
.where('assets.visibility', '!=', AssetVisibility.TIMELINE)
.deleteFrom('memory_asset')
.using('asset')
.whereRef('memory_asset.assetsId', '=', 'asset.id')
.where('asset.visibility', '!=', AssetVisibility.TIMELINE)
.execute();
return this.db
.deleteFrom('memories')
.deleteFrom('memory')
.where('createdAt', '<', DateTime.now().minus({ days: 30 }).toJSDate())
.where('isSaved', '=', false)
.execute();
@@ -31,7 +31,7 @@ export class MemoryRepository implements IBulkAsset {
searchBuilder(ownerId: string, dto: MemorySearchDto) {
return this.db
.selectFrom('memories')
.selectFrom('memory')
.$if(dto.isSaved !== undefined, (qb) => qb.where('isSaved', '=', dto.isSaved!))
.$if(dto.type !== undefined, (qb) => qb.where('type', '=', dto.type!))
.$if(dto.for !== undefined, (qb) =>
@@ -62,16 +62,16 @@ export class MemoryRepository implements IBulkAsset {
.select((eb) =>
jsonArrayFrom(
eb
.selectFrom('assets')
.selectAll('assets')
.innerJoin('memories_assets_assets', 'assets.id', 'memories_assets_assets.assetsId')
.whereRef('memories_assets_assets.memoriesId', '=', 'memories.id')
.orderBy('assets.fileCreatedAt', 'asc')
.where('assets.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
.where('assets.deletedAt', 'is', null),
.selectFrom('asset')
.selectAll('asset')
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetsId')
.whereRef('memory_asset.memoriesId', '=', 'memory.id')
.orderBy('asset.fileCreatedAt', 'asc')
.where('asset.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
.where('asset.deletedAt', 'is', null),
).as('assets'),
)
.selectAll('memories')
.selectAll('memory')
.orderBy('memoryAt', 'desc')
.execute();
}
@@ -83,11 +83,11 @@ export class MemoryRepository implements IBulkAsset {
async create(memory: Insertable<MemoryTable>, assetIds: Set<string>) {
const id = await this.db.transaction().execute(async (tx) => {
const { id } = await tx.insertInto('memories').values(memory).returning('id').executeTakeFirstOrThrow();
const { id } = await tx.insertInto('memory').values(memory).returning('id').executeTakeFirstOrThrow();
if (assetIds.size > 0) {
const values = [...assetIds].map((assetId) => ({ memoriesId: id, assetsId: assetId }));
await tx.insertInto('memories_assets_assets').values(values).execute();
await tx.insertInto('memory_asset').values(values).execute();
}
return id;
@@ -98,13 +98,13 @@ export class MemoryRepository implements IBulkAsset {
@GenerateSql({ params: [DummyValue.UUID, { ownerId: DummyValue.UUID, isSaved: true }] })
async update(id: string, memory: Updateable<MemoryTable>) {
await this.db.updateTable('memories').set(memory).where('id', '=', id).execute();
await this.db.updateTable('memory').set(memory).where('id', '=', id).execute();
return this.getByIdBuilder(id).executeTakeFirstOrThrow();
}
@GenerateSql({ params: [DummyValue.UUID] })
async delete(id: string) {
await this.db.deleteFrom('memories').where('id', '=', id).execute();
await this.db.deleteFrom('memory').where('id', '=', id).execute();
}
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
@@ -115,7 +115,7 @@ export class MemoryRepository implements IBulkAsset {
}
const results = await this.db
.selectFrom('memories_assets_assets')
.selectFrom('memory_asset')
.select(['assetsId'])
.where('memoriesId', '=', id)
.where('assetsId', 'in', assetIds)
@@ -131,7 +131,7 @@ export class MemoryRepository implements IBulkAsset {
}
await this.db
.insertInto('memories_assets_assets')
.insertInto('memory_asset')
.values(assetIds.map((assetId) => ({ memoriesId: id, assetsId: assetId })))
.execute();
}
@@ -143,27 +143,23 @@ export class MemoryRepository implements IBulkAsset {
return;
}
await this.db
.deleteFrom('memories_assets_assets')
.where('memoriesId', '=', id)
.where('assetsId', 'in', assetIds)
.execute();
await this.db.deleteFrom('memory_asset').where('memoriesId', '=', id).where('assetsId', 'in', assetIds).execute();
}
private getByIdBuilder(id: string) {
return this.db
.selectFrom('memories')
.selectAll('memories')
.selectFrom('memory')
.selectAll('memory')
.select((eb) =>
jsonArrayFrom(
eb
.selectFrom('assets')
.selectAll('assets')
.innerJoin('memories_assets_assets', 'assets.id', 'memories_assets_assets.assetsId')
.whereRef('memories_assets_assets.memoriesId', '=', 'memories.id')
.orderBy('assets.fileCreatedAt', 'asc')
.where('assets.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
.where('assets.deletedAt', 'is', null),
.selectFrom('asset')
.selectAll('asset')
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetsId')
.whereRef('memory_asset.memoriesId', '=', 'memory.id')
.orderBy('asset.fileCreatedAt', 'asc')
.where('asset.visibility', '=', sql.lit(AssetVisibility.TIMELINE))
.where('asset.deletedAt', 'is', null),
).as('assets'),
)
.where('id', '=', id)