Changeset - f399e4d14553
[Not reviewed]
0 10 0
Lance Edgar (lance) - 2 months ago 2024-08-19 14:14:06
lance@edbob.org
fix: deprecate `config.rattail_engines` in favor of `appdb_engines`
10 files changed with 41 insertions and 32 deletions:
0 comments (0 inline, 0 general)
rattail/commands/checkdb.py
Show inline comments
 
@@ -42,7 +42,7 @@ def checkdb(
 

	
 
    config = ctx.parent.rattail_config
 
    try:
 
        with config.rattail_engine.begin() as cxn:
 
        with config.appdb_engine.begin() as cxn:
 
            cxn.execute(sa.text("select version()"))
 
    except sa.exc.OperationalError as e:
 
        sys.stderr.write("\nfailed to connect to DB!\n\n{}\n".format(e))
rattail/config.py
Show inline comments
 
@@ -90,11 +90,6 @@ class RattailConfig(WuttaConfig):
 
        # this is false, unless/until it becomes true
 
        self.versioning_has_been_enabled = False
 

	
 
        # TODO: deprecate / remove these
 
        if hasattr(self, 'appdb_engines'):
 
            self.rattail_engines = self.appdb_engines
 
            self.rattail_engine = self.appdb_engine
 

	
 
        # configure session if applicable
 
        from rattail.db import Session
 
        if Session:
 
@@ -111,6 +106,20 @@ class RattailConfig(WuttaConfig):
 
            from rattail.db.config import configure_session
 
            configure_session(self, Session)
 

	
 
    @property
 
    def rattail_engines(self):
 
        warnings.warn("config.rattail_engines is deprecated; "
 
                      "please use config.appdb_engines instead",
 
                      DeprecationWarning, stacklevel=2)
 
        return self.appdb_engines
 

	
 
    @property
 
    def rattail_engine(self):
 
        warnings.warn("config.rattail_engine is deprecated; "
 
                      "please use config.appdb_engine instead",
 
                      DeprecationWarning, stacklevel=2)
 
        return self.appdb_engine
 

	
 
    @property
 
    def prioritized_files(self):
 
        """
rattail/datasync/rattail.py
Show inline comments
 
@@ -41,7 +41,7 @@ class RattailWatcher(DataSyncWatcher):
 

	
 
    def __init__(self, *args, **kwargs):
 
        super().__init__(*args, **kwargs)
 
        self.engine = self.config.rattail_engines[self.dbkey]
 
        self.engine = self.config.appdb_engines[self.dbkey]
 
        self.topo_sortkey = make_topo_sortkey(self.app.model)
 

	
 
    def get_changes(self, lastrun):
 
@@ -176,7 +176,7 @@ class RattailConsumer(DataSyncConsumer):
 

	
 
    def __init__(self, *args, **kwargs):
 
        super().__init__(*args, **kwargs)
 
        self.engine = self.config.rattail_engines[self.dbkey]
 
        self.engine = self.config.appdb_engines[self.dbkey]
 
        self.model = self.get_data_model()
 
        self.topo_sortkey = make_topo_sortkey(self.model)
 

	
 
@@ -429,7 +429,7 @@ class FromRattailToRattailExportConsumer(FromRattailToRattailBase):
 

	
 
    def __init__(self, *args, **kwargs):
 
        super().__init__(*args, **kwargs)
 
        self.target_engine = self.config.rattail_engines[self.dbkey]
 
        self.target_engine = self.config.appdb_engines[self.dbkey]
 
        self.model = self.app.model
 

	
 
    def make_target_session(self):
 
@@ -471,8 +471,8 @@ class FromRattailToRattailImportConsumer(FromRattailToRattailBase):
 

	
 
    def __init__(self, *args, **kwargs):
 
        super().__init__(*args, **kwargs)
 
        self.host_engine = self.config.rattail_engines[self.watcher.dbkey]
 
        self.local_engine = self.config.rattail_engines[self.dbkey]
 
        self.host_engine = self.config.appdb_engines[self.watcher.dbkey]
 
        self.local_engine = self.config.appdb_engines[self.dbkey]
 
        self.model = self.app.model
 

	
 
    def process_changes(self, session, changes):
rattail/db/alembic/env.py
Show inline comments
 
@@ -42,7 +42,7 @@ def run_migrations_offline():
 
    script output.
 

	
 
    """
 
    engine = rattail_config.rattail_engine
 
    engine = rattail_config.appdb_engine
 
    context.configure(
 
        url=engine.url,
 
        target_metadata=target_metadata)
 
@@ -58,7 +58,7 @@ def run_migrations_online():
 
    and associate a connection with the context.
 

	
 
    """
 
    engine = rattail_config.rattail_engine
 
    engine = rattail_config.appdb_engine
 
    connection = engine.connect()
 
    context.configure(
 
        connection=connection,
rattail/db/handler.py
Show inline comments
 
@@ -78,7 +78,7 @@ class DatabaseHandler(GenericHandler):
 
        # cf. https://alembic.sqlalchemy.org/en/latest/cookbook.html#test-current-database-revision-is-at-head-s
 
        alembic_config = self.make_alembic_config()
 
        script = ScriptDirectory.from_config(alembic_config)
 
        with self.config.rattail_engine.begin() as connection:
 
        with self.config.appdb_engine.begin() as connection:
 
            context = MigrationContext.configure(connection)
 
            return set(context.get_current_heads()) == set(script.get_heads())
 

	
rattail/importing/rattail.py
Show inline comments
 
@@ -194,7 +194,7 @@ class FromRattailToRattailImport(FromRattailToRattailBase, FromRattailHandler, T
 
        return self.config.node_title(default="Rattail (local)")
 

	
 
    def make_host_session(self):
 
        return self.app.make_session(bind=self.config.rattail_engines[self.dbkey])
 
        return self.app.make_session(bind=self.config.appdb_engines[self.dbkey])
 

	
 

	
 
class FromRattailToRattailExport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
 
@@ -218,7 +218,7 @@ class FromRattailToRattailExport(FromRattailToRattailBase, FromRattailHandler, T
 
        return "{} ({})".format(self.config.app_title(default="Rattail"), self.dbkey)
 

	
 
    def make_session(self):
 
        return self.app.make_session(bind=self.config.rattail_engines[self.dbkey])
 
        return self.app.make_session(bind=self.config.appdb_engines[self.dbkey])
 

	
 

	
 
class FromRattail(FromSQLAlchemySameToSame):
rattail/luigi/handler.py
Show inline comments
 
@@ -270,9 +270,9 @@ class LuigiHandler(GenericHandler):
 
        # foribly recreate the connection pool for all overnight task
 
        # runs.  would be nice to be more selective but this seems to
 
        # work okay for now...
 
        pool = self.config.rattail_engine.pool
 
        pool = self.config.appdb_engine.pool
 
        pool.dispose()
 
        self.config.rattail_engine.pool = pool.recreate()
 
        self.config.appdb_engine.pool = pool.recreate()
 

	
 
        # run command in subprocess
 
        curdir = os.getcwd()
tests/__init__.py
Show inline comments
 
@@ -53,7 +53,7 @@ else:
 
        host_engine_url = os.environ.get('RATTAIL_TEST_HOST_ENGINE_URL')
 

	
 
        def postgresql(self):
 
            return self.config.rattail_engine.url.get_dialect().name == 'postgresql'
 
            return self.config.appdb_engine.url.get_dialect().name == 'postgresql'
 

	
 
        def setUp(self):
 
            self.setup_rattail()
 
@@ -67,11 +67,11 @@ else:
 
            self.rattail_config = config
 

	
 
            engine = sa.create_engine(self.engine_url)
 
            config.rattail_engines = {'default': engine}
 
            config.rattail_engine = engine
 
            config.appdb_engines = {'default': engine}
 
            config.appdb_engine = engine
 

	
 
            if self.host_engine_url:
 
                config.rattail_engines['host'] = sa.create_engine(self.host_engine_url)
 
                config.appdb_engines['host'] = sa.create_engine(self.host_engine_url)
 

	
 
            model = self.get_rattail_model()
 
            model.Base.metadata.create_all(bind=engine)
 
@@ -83,7 +83,7 @@ else:
 
            self.session.close()
 
            Session.configure(bind=None, rattail_config=None)
 
            model = self.get_rattail_model()
 
            model.Base.metadata.drop_all(bind=self.rattail_config.rattail_engine)
 
            model.Base.metadata.drop_all(bind=self.rattail_config.appdb_engine)
 

	
 
        def make_rattail_config(self, **kwargs):
 
            kwargs.setdefault('files', [])
tests/importing/test_rattail.py
Show inline comments
 
@@ -19,10 +19,10 @@ else:
 
        def setup_rattail(self):
 
            super().setup_rattail()
 

	
 
            if 'host' not in self.config.rattail_engines:
 
                self.config.rattail_engines['host'] = sa.create_engine('sqlite://')
 
            if 'host' not in self.config.appdb_engines:
 
                self.config.appdb_engines['host'] = sa.create_engine('sqlite://')
 

	
 
            self.host_engine = self.config.rattail_engines['host']
 
            self.host_engine = self.config.appdb_engines['host']
 
            self.config.setdefault('rattail', 'timezone.default', 'America/Chicago')
 
            self.config.setdefault('rattail.db', 'keys', 'default, host')
 
            self.config.setdefault('rattail.db', 'host.url', str(self.host_engine.url))
 
@@ -35,7 +35,7 @@ else:
 

	
 
            self.host_session.close()
 
            model = self.get_rattail_model()
 
            model.Base.metadata.drop_all(bind=self.config.rattail_engines['host'])
 
            model.Base.metadata.drop_all(bind=self.config.appdb_engines['host'])
 

	
 
            if hasattr(self, 'tempio'):
 
                self.tempio = None
 
@@ -52,7 +52,7 @@ else:
 
            handler = self.make_handler()
 
            session = handler.make_host_session()
 
            self.assertIsInstance(session, SessionBase)
 
            self.assertIs(session.bind, self.config.rattail_engine)
 
            self.assertIs(session.bind, self.config.appdb_engine)
 

	
 

	
 
    class TestFromRattailToRattail(DualRattailTestCase, ImporterTester):
 
@@ -72,7 +72,7 @@ else:
 
            handler = self.make_handler()
 
            session = handler.make_session()
 
            self.assertIsInstance(session, SessionBase)
 
            self.assertIs(session.bind, self.config.rattail_engine)
 
            self.assertIs(session.bind, self.config.appdb_engine)
 

	
 
        def test_make_host_session(self):
 

	
 
@@ -81,7 +81,7 @@ else:
 
            self.assertRaises(KeyError, handler.make_host_session)
 

	
 
            # alternate dbkey
 
            self.config.rattail_engines['other'] = self.config.rattail_engines['host']
 
            self.config.appdb_engines['other'] = self.config.appdb_engines['host']
 
            handler = self.make_handler(dbkey='other')
 
            session = handler.make_host_session()
 
            self.assertIsInstance(session, SessionBase)
tests/test_config.py
Show inline comments
 
@@ -33,8 +33,8 @@ class TestRattailConfig(FileConfigTestCase):
 
            self.assertIs(session.rattail_config, config)
 
        else:
 
            # no sqlalchemy, so no rattail engines
 
            self.assertFalse(hasattr(config, 'rattail_engines'))
 
            self.assertFalse(hasattr(config, 'rattail_engine'))
 
            self.assertFalse(hasattr(config, 'appdb_engines'))
 
            self.assertFalse(hasattr(config, 'appdb_engine'))
 

	
 
        # default db
 
        config = self.make_config(defaults={
0 comments (0 inline, 0 general)