1212
1313import sqlalchemy
1414
15- from .engine import engine
15+ from .. config import Config
1616
1717
1818# for now, schema updates are SQL only and work on PostgreSQL, only.
@@ -48,7 +48,9 @@ class DatabaseSchemaUpdater:
4848 def __init__ (self ):
4949 """Update the database schema if necessary."""
5050 # Try to create database table for schema version
51- with engine .begin () as connection :
51+ with Config () as config :
52+ self .engine = sqlalchemy .create_engine (config ["database_connection_string" ])
53+ with self .engine .begin () as connection :
5254 connection .execute (
5355 sqlalchemy .text (
5456 """
@@ -65,7 +67,7 @@ def __init__(self):
6567 @property
6668 def installed_version (self ):
6769 """Return current version."""
68- with engine .connect () as connection :
70+ with self . engine .connect () as connection :
6971 installed_version = connection .execute (
7072 sqlalchemy .text (
7173 """
@@ -92,18 +94,17 @@ def update_to_latest(self):
9294 file = sys .stderr ,
9395 flush = True , # so that we don’t seem without work
9496 )
95- with engine .begin () as connection :
97+ with self . engine .connect () as connection :
9698 next_version = self .installed_version + 1
9799 connection .execute (sqlalchemy .text (SCHEMA_UPDATES [next_version ]))
98100 self .set_schema_version (next_version )
99101 installed_version = self .installed_version
100102
101- @classmethod
102- def set_schema_version (cls , version ):
103+ def set_schema_version (self , version ):
103104 """Set the schema version (without running update scripts)."""
104- if version == cls .LATEST :
105+ if version == self .LATEST :
105106 version = max (SCHEMA_UPDATES .keys ())
106- with engine .begin () as connection :
107+ with self . engine .begin () as connection :
107108 connection .execute (
108109 sqlalchemy .text (
109110 """
0 commit comments