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 db migration with postgres #1679

Merged
merged 2 commits into from Jun 14, 2019

Conversation

plettich
Copy link
Member

PostgreSQL (and Oracle and SQLite) use sequences for autoincrement columns.
If no sequence is given, one will be created automatically which clashes
with the required one in models.py
We have to create the required sequence manually but only if the backend
supports it.
Actually this affects all migration scripts which create columns with an
auto_increment attribute.

Fixes #1676

PostgreSQL (and Oracle and SQLite) use sequences for autoincrement columns.
If no sequence is given, one will be created automatically which clashes
with the required one in `models.py`
We have to create the required sequence manually but only if the backend
supports it.
Actually this affects all migration scripts which create columns with an
auto_increment attribute.

Fixes #1676
@plettich plettich requested a review from a team June 13, 2019 09:51
Copy link
Member

@cornelinux cornelinux left a comment

Choose a reason for hiding this comment

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

lgtm. Thanks!

def upgrade():
try:
create_seq('tokenowner_seq')
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good! But could you wrap this call in a try-except block? This way, if creating the sequence fails for any reason, we will at least create the tokenowner table.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in beb31af

@codecov
Copy link

codecov bot commented Jun 13, 2019

Codecov Report

Merging #1679 into branch-3.0 will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff               @@
##           branch-3.0    #1679      +/-   ##
==============================================
- Coverage       96.98%   96.93%   -0.05%     
==============================================
  Files             148      148              
  Lines           17849    17738     -111     
==============================================
- Hits            17310    17195     -115     
- Misses            539      543       +4
Impacted Files Coverage Δ
privacyidea/lib/eventhandler/base.py 95.96% <0%> (-2.69%) ⬇️
privacyidea/api/auth.py 95.53% <0%> (-0.42%) ⬇️

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 3abf02e...beb31af. Read the comment docs.

@fredreichbier
Copy link
Contributor

Looks good, thanks!

@fredreichbier fredreichbier merged commit 8669f1f into branch-3.0 Jun 14, 2019
@fredreichbier fredreichbier deleted the 1676/fix_postgres_db_migration branch June 14, 2019 08:29
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.

None yet

3 participants