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

Use psql to run migrations #73

Merged
merged 10 commits into from
Jul 17, 2020
Merged

Use psql to run migrations #73

merged 10 commits into from
Jul 17, 2020

Conversation

k4nar
Copy link
Contributor

@k4nar k4nar commented Jul 15, 2020

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.

Copy link
Contributor

@ewjoachim ewjoachim left a 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 ewjoachim marked this pull request as draft July 16, 2020 09:19
@k4nar
Copy link
Contributor Author

k4nar commented Jul 16, 2020

@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 --meta-psql:do-until-0 stuff, which is very specific to PeopleDoc and undocumented.

The new code is still handling the --meta-psql:do-until-0 blocks, but in a much less intrusive way. And being compatible with psql opens the door more more customization on the DBA side, from PeopleDoc or wherever.


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 :( .

Comment on lines 34 to 37
for name in ['HOST', 'PORT', 'DBNAME', 'USERNAME', 'PASSWORD']:
value = getattr(self.settings, name)
if value:
creds += ['--' + name.lower(), value]
Copy link
Contributor

@ewjoachim ewjoachim Jul 16, 2020

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@ewjoachim
Copy link
Contributor

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.

@k4nar k4nar changed the title [WIP] Use psql to run migrations Use psql to run migrations Jul 17, 2020
@k4nar k4nar marked this pull request as ready for review July 17, 2020 14:05
@k4nar
Copy link
Contributor Author

k4nar commented Jul 17, 2020

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

oops

Copy link
Contributor

@ewjoachim ewjoachim left a 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.

Comment on lines 34 to 37
for name in ['HOST', 'PORT', 'DBNAME', 'USERNAME', 'PASSWORD']:
value = getattr(self.settings, name)
if value:
creds += ['--' + name.lower(), value]
Copy link
Contributor

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
Copy link

codecov bot commented Jul 17, 2020

Codecov Report

Merging #73 into master will increase coverage by 1.09%.
The diff coverage is 96.96%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
#integration 57.09% <96.96%> (+7.60%) ⬆️
#unit 59.33% <18.18%> (-4.43%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
septentrion/configuration.py 82.95% <ø> (-0.20%) ⬇️
septentrion/migration.py 80.21% <0.00%> (+0.87%) ⬆️
septentrion/runner.py 100.00% <100.00%> (+20.40%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 71a4691...faa427e. Read the comment docs.

@k4nar
Copy link
Contributor Author

k4nar commented Jul 17, 2020

Thanks @ewjoachim !

@k4nar k4nar merged commit 4b04905 into master Jul 17, 2020
@k4nar k4nar deleted the psql branch July 17, 2020 15:09
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