-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use psql to run migrations #73
Conversation
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'm wondering if it would be worth it to keep a Psycopg2Executor alongside a PsqlExecutor. We still entertain the idea that septentrion could evolve to a tool that is not solely centered around PeopleDoc migrations. Doesn't have to be, though. What's your take ?
@ewjoachim : I think keeping two different runners would make things more complicated to explain & maintain. The code that is being replaced was written specifically for PeopleDoc migrations, to handle the The new code is still handling the I do understand that adding a direct dependency to the psql binary is a big downside though. But it's the only solution I see for our internal issue :( . |
septentrion/runner.py
Outdated
for name in ['HOST', 'PORT', 'DBNAME', 'USERNAME', 'PASSWORD']: | ||
value = getattr(self.settings, name) | ||
if value: | ||
creds += ['--' + name.lower(), value] |
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 think it would be much clearer to pass all those via environment. What do you think ?
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.
If I define env vars, I must also pass mandatory env vars like PATH, otherwise psql won't be found. I guess I could do something like env={'PGHOST': self.settings.HOST [...], **os.environ}
, but I don't know if it's a good practice.
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.
Yes, I was thinking of doing that. Is there any reason this wouldn't be a good practice ?
(I really wish subprocess had an "additional_env" or "env_override", but eh).
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.
psql will prioritize the cmd arguments over the env vars. I'm not sure of the priority in Septentrion, but passing explicit values to psql will ensure that we don't end up in a situation were Septentrion connects to a DB, but psql launches the migrations in another one.
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.
not convinced but this can be dealt with later.
Ok, let's go with psql and no psycopg2. Does this means we can get rid of the dependency ? I think not from the top of my head, but I haven't checked. |
This is now ready for review. |
@@ -22,7 +22,7 @@ | |||
folder.expanduser().resolve() / DEDICATED_CONFIGURATION_FILENAME | |||
for folder in CONFIGURATION_PATHS | |||
] | |||
print(DEDICATED_CONFIGURATION_FILES) | |||
|
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.
oops
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 think this is sufficient for now. Thanks a lot. Let's fix the CI and make a quick release. We'll smooth it later.
septentrion/runner.py
Outdated
for name in ['HOST', 'PORT', 'DBNAME', 'USERNAME', 'PASSWORD']: | ||
value = getattr(self.settings, name) | ||
if value: | ||
creds += ['--' + name.lower(), value] |
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.
not convinced but this can be dealt with later.
Codecov Report
@@ Coverage Diff @@
## master #73 +/- ##
==========================================
+ Coverage 76.41% 77.51% +1.09%
==========================================
Files 15 15
Lines 687 627 -60
Branches 92 79 -13
==========================================
- Hits 525 486 -39
+ Misses 147 130 -17
+ Partials 15 11 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Thanks @ewjoachim ! |
Septentrion is not compatible with migrations containing
psql
instructions. Those can be quite useful for data migrations sometimes (eg: to use\gset
or\gexec
).This PR tries to replace the migration runner by a wrapper around
psql
. This is still a WIP.