简体   繁体   English

复制带时间戳的文件、重命名并即时更改内容

[英]Copying a timestamped file, renaming it and changing contents on the fly

I had about 30 migration files (sequelize) looking like the following that I wanted to copy into migrations for another table, while changing the migration file's name (sequelize relies on utc-timestamp) and changing the table-name in the file at the same time:我有大约 30 个迁移文件(续集),如下所示,我想将它们复制到另一个表的迁移中,同时更改迁移文件的名称(续集依赖于 utc-timestamp)并同时更改文件中的表名时间:

"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.addColumn("Providers", "column-name", { type: Sequelize.DECIMAL(8, 2) });
  },

  down: (queryInterface, Sequelize) => {
    return queryInterface.removeColumn("Providers", "column-name");
  }
};
for f in migrations/*[ce]c-to*; do cat "$f" | sed 's/Providers/PracticeAssignments/g' > migrations/$(date +'%Y%m%d%H%M%S' -u)-$(echo $f | sed 's/provider/practice-assignment/g' | cut -d'-' -f2-); done

^^that script seemed to have done the trick! ^^那个脚本似乎成功了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM