-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Conversation
* 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
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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+/, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to move this to metautil and implement like this one:
https://github.com/metarhia/metautil/blob/a8c48888e6b18a760e6e7f051582c7d47f52e740/lib/utilities.js#L96-L102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migration folders
to the old version
npm t
)npm run fmt
)