Merge ~alexsander-souza/maas:lp1966506_check_pg_version into maas:master

Proposed by Alexsander de Souza
Status: Merged
Approved by: Alexsander de Souza
Approved revision: 2b70805907d0f7feec3d23d48ae939f7e6db05fc
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~alexsander-souza/maas:lp1966506_check_pg_version
Merge into: maas:master
Diff against target: 27 lines (+9/-0)
1 file modified
src/maasserver/management/commands/dbupgrade.py (+9/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Christian Grabowski Approve
Review via email: mp+417991@code.launchpad.net

Commit message

Check pg version before applying migrations

Some migrations may fail on earlier versions of postgres, leaving the system in a broken state. This aborts the process before any change is made.

Fixes LP#1966506

To post a comment you must log in.
Revision history for this message
Christian Grabowski (cgrabowski) wrote :

+1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1966506_check_pg_version lp:~alexsander-souza/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2b70805907d0f7feec3d23d48ae939f7e6db05fc

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/management/commands/dbupgrade.py b/src/maasserver/management/commands/dbupgrade.py
2index 0d2bd5f..ddf5582 100644
3--- a/src/maasserver/management/commands/dbupgrade.py
4+++ b/src/maasserver/management/commands/dbupgrade.py
5@@ -13,6 +13,8 @@ from django.core.management import call_command
6 from django.core.management.base import BaseCommand
7 from django.db import connections, DEFAULT_DB_ALIAS
8
9+from maasserver.plugin import PGSQL_MIN_VERSION, UnsupportedDBException
10+
11
12 class Command(BaseCommand):
13 help = "Upgrades database schema for MAAS regiond."
14@@ -100,6 +102,13 @@ class Command(BaseCommand):
15 database = options.get("database")
16 no_triggers = options.get("no_triggers")
17
18+ # Check database version
19+ conn = connections[database]
20+ conn.ensure_connection()
21+ pg_ver = conn.cursor().connection.server_version
22+ if pg_ver // 100 < PGSQL_MIN_VERSION:
23+ raise UnsupportedDBException(pg_ver)
24+
25 # First, drop any views that may already exist. We don't want views
26 # that that depend on a particular schema to prevent schema
27 # changes due to the dependency. The views will be recreated at the

Subscribers

People subscribed via source and target branches