Commit 4df3e5cf authored by nanahira's avatar nanahira

migrate script

parent 27c00edd
Pipeline #5121 passed with stage
in 3 minutes and 39 seconds
...@@ -371,23 +371,18 @@ export class AppService extends ConsoleLogger { ...@@ -371,23 +371,18 @@ export class AppService extends ConsoleLogger {
return new BlankReturnMessageDto(200, 'success'); return new BlankReturnMessageDto(200, 'success');
} }
/*
async migrateFilesField() { async migrateFilesField() {
const archives = await this.db.getRepository(Archive).find({ select: ['id', 'files'] }); const archives = await this.db.getRepository(Archive).find({ select: ['id', 'files'], where: { files: IsNull() } });
await this.db.transaction(async (edb) => { await this.db.transaction(async (edb) => {
for (const a of archives) { for (const a of archives) {
this.log(`Processing archive ${a.id} with ${a.files.length} files.`); this.log(`Processing archive ${a.id}.`);
const files = a.files.map((f) => { const fileEnts = await this.db.getRepository(ArchiveFile).find({ select: ['path'], where: { archive: a } });
const fileEnt = ArchiveFile.fromPath(f); this.log(`${fileEnts.length} files found for archive ${a.id}`);
fileEnt.archive = a; a.files = fileEnts.map((f) => f.path);
return fileEnt; await edb.getRepository(Archive).save(a);
});
await edb.getRepository(ArchiveFile).save(files);
} }
}); });
this.log(`Done.`); this.log(`Done.`);
return new BlankReturnMessageDto(200, 'success'); return new BlankReturnMessageDto(200, 'success');
} }
*/
} }
...@@ -15,8 +15,8 @@ export class Archive extends TimeBase { ...@@ -15,8 +15,8 @@ export class Archive extends TimeBase {
@PrimaryGeneratedColumn({ type: 'int8' }) @PrimaryGeneratedColumn({ type: 'int8' })
id: number; id: number;
//@Column('varchar', { length: 256, array: true }) @Column('varchar', { length: 256, array: true, nullable: true })
//files: string[]; files: string[];
@OneToMany(() => ArchiveFile, (file) => file.archive, { cascade: true }) @OneToMany(() => ArchiveFile, (file) => file.archive, { cascade: true })
containingFiles: ArchiveFile[]; containingFiles: ArchiveFile[];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment