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 {
return new BlankReturnMessageDto(200, 'success');
}
/*
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) => {
for (const a of archives) {
this.log(`Processing archive ${a.id} with ${a.files.length} files.`);
const files = a.files.map((f) => {
const fileEnt = ArchiveFile.fromPath(f);
fileEnt.archive = a;
return fileEnt;
});
await edb.getRepository(ArchiveFile).save(files);
this.log(`Processing archive ${a.id}.`);
const fileEnts = await this.db.getRepository(ArchiveFile).find({ select: ['path'], where: { archive: a } });
this.log(`${fileEnts.length} files found for archive ${a.id}`);
a.files = fileEnts.map((f) => f.path);
await edb.getRepository(Archive).save(a);
}
});
this.log(`Done.`);
return new BlankReturnMessageDto(200, 'success');
}
*/
}
......@@ -15,8 +15,8 @@ export class Archive extends TimeBase {
@PrimaryGeneratedColumn({ type: 'int8' })
id: number;
//@Column('varchar', { length: 256, array: true })
//files: string[];
@Column('varchar', { length: 256, array: true, nullable: true })
files: string[];
@OneToMany(() => ArchiveFile, (file) => file.archive, { cascade: true })
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