Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix migration commands #219

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

WIP: Fix migration commands #219

wants to merge 2 commits into from

Conversation

lundibundi
Copy link
Member

  • on no prev version - copy current schemas as old version
  • upon executing a 'g' command create a new version history and
    migration folders
  • store time in migration version
  • upon creating a new version copy only "changes" schemas compared
    to the old version
  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

* on no prev version - copy current schemas as old version
* upon executing a 'g' command create a new version history and
  migration folders
* store time in migration version
* upon creating a new version copy only "changes" schemas compared
  to the old version
@tshemsedinov tshemsedinov changed the title Fix migration commands WIP: Fix migration commands Oct 15, 2021
Copy link
Member

@tshemsedinov tshemsedinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @lundibundi great work but I need more time to review this, feel free to commit fixups, I will add WIP to this PR.


const makeVersionName = (v, date) => `${date}--v${v}`;

const cpdir = async (from, to, filter) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for future todo: we may move this function to metautil

const databasePath = path.join(modelPath, '.database.js');
const existingFile = await fsp.readFile(databasePath, { encoding: 'utf8' });
const newFile = existingFile.replace(
/version: \d+/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd better use string functions instead of regex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it much harder to check that we have exactly /version: \d+/, (checking numbers as well) and therefore possibly replacing the wrong thing in a file.

let version = 0;
let previousName = '';
for (const folder of folders) {
if (!folder.isDirectory()) continue;
const { name } = folder;
const v = parseInt(name.substring(name.indexOf('v') + 1), 10);
const v = parseInt(/v(\d+)/.exec(name)[1], 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

const migrationPath = path.join(modelPath, 'migration');
const currentModel = await loadModel(modelPath);
const { name, driver, version } = currentModel.database;
const now = new Date().toISOString().replace(/:/g, '-').split('.')[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants