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

Fix migration bug where using -- as an actual string value gets lost #28

Merged
merged 3 commits into from
Apr 30, 2017

Conversation

theogravity
Copy link
Collaborator

Fixes #27

@theogravity
Copy link
Collaborator Author

@koistya

src/Database.js Outdated
migration.down = down.replace(/^--.*?$/gm, '').trim(); // and trim whitespaces
migration.up = up.replace(/^-- Up.*?$/gm, '').trim(); // Remove comments
migration.up = migration.up.replace(/^-+$/gm, '').trim();
migration.down = down.replace(/^-- Down.*?$/gm, '').trim(); // and trim whitespaces
Copy link

Choose a reason for hiding this comment

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

I think you don't need this replace(): down doesn't contain the comment, since we split on /^--\s+?down/mi

src/Database.js Outdated
migration.up = up.replace(/^-- Up.*?$/gm, '').trim(); // Remove comments
migration.up = migration.up.replace(/^-+$/gm, '').trim();
migration.down = down.replace(/^-- Down.*?$/gm, '').trim(); // and trim whitespaces
migration.down = migration.down.replace(/^-+$/gm, '').trim(); // and trim whitespaces
Copy link

@BeLi4L BeLi4L Apr 14, 2017

Choose a reason for hiding this comment

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

Couldn't we keep comments and just do migration.down = down.trim();? 🤔

This would prevent future issues with dashes in values.

@theogravity
Copy link
Collaborator Author

thanks @BeLi4L for the review - was really busy at work since then, will change now

@koistya
Copy link
Member

koistya commented Apr 23, 2017

@theogravity what do you think about detecting comments by using ^-- .* (having a space after two dashes)?

@theogravity
Copy link
Collaborator Author

theogravity commented Apr 25, 2017

I'd rather do that approach instead

@theogravity
Copy link
Collaborator Author

theogravity commented Apr 25, 2017

@koistya @BeLi4L updated pr

@@ -167,8 +167,8 @@ class Database {
reject(new Error(message));
} else {
/* eslint-disable no-param-reassign */
migration.up = up.replace(/^--.*?$/gm, '').trim(); // Remove comments
migration.down = down.replace(/^--.*?$/gm, '').trim(); // and trim whitespaces
migration.up = up.replace(/^-- .*?$/gm, '').trim();// Remove comments
Copy link

Choose a reason for hiding this comment

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

Thanks @theogravity 😁

Quick quesiton: do we really need to remove comments? Simply doing migration.up = up.trim() (same as migration.down) would prevent future issues like the one I just had with TLS certificates ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i think @koistya could prob chime in on that one

@theogravity
Copy link
Collaborator Author

I'm going to merge this in - it's been sitting around so long and the tests are not breaking.

@theogravity theogravity merged commit d9e8af4 into master Apr 30, 2017
@theogravity theogravity deleted the fix-migration-bug branch April 30, 2017 23:27
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.

3 participants