mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-11-03 23:33:41 +00:00 
			
		
		
		
	feat: add ability to skip migrations
This feature can be used in order to handle conflicting migrations
This commit is contained in:
		@ -34,8 +34,9 @@ It will check current settings on common errors and compare configuration with k
 | 
			
		||||
 | 
			
		||||
Base configuration settings.
 | 
			
		||||
 | 
			
		||||
* ``include`` - path to directory with configuration files overrides, string, required.
 | 
			
		||||
* ``apply_migrations`` - perform migrations on application start, boolean, optional, default ``yes``. Useful if you are using git version. Note, however, that this option must be changed only if you know what to do and going to handle migrations automatically.
 | 
			
		||||
* ``database`` - path to SQLite database, string, required.
 | 
			
		||||
* ``include`` - path to directory with configuration files overrides, string, required.
 | 
			
		||||
* ``logging`` - path to logging configuration, string, required. Check ``logging.ini`` for reference.
 | 
			
		||||
* ``suppress_http_log_errors`` - suppress http log errors, boolean, optional, default ``no``. If set to ``yes``, any http log errors (e.g. if web server is not available, but http logging is enabled) will be suppressed.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
[settings]
 | 
			
		||||
include = ahriman.ini.d
 | 
			
		||||
logging = ahriman.ini.d/logging.ini
 | 
			
		||||
apply_migrations = yes
 | 
			
		||||
database = /var/lib/ahriman/ahriman.db
 | 
			
		||||
suppress_http_log_errors = yes
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -30,17 +30,21 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
 | 
			
		||||
    "settings": {
 | 
			
		||||
        "type": "dict",
 | 
			
		||||
        "schema": {
 | 
			
		||||
            "include": {
 | 
			
		||||
                "type": "path",
 | 
			
		||||
                "coerce": "absolute_path",
 | 
			
		||||
                "required": True,
 | 
			
		||||
                "path_exists": True,
 | 
			
		||||
            "apply_migrations": {
 | 
			
		||||
                "type": "boolean",
 | 
			
		||||
                "coerce": "boolean",
 | 
			
		||||
            },
 | 
			
		||||
            "database": {
 | 
			
		||||
                "type": "path",
 | 
			
		||||
                "coerce": "absolute_path",
 | 
			
		||||
                "required": True,
 | 
			
		||||
            },
 | 
			
		||||
            "include": {
 | 
			
		||||
                "type": "path",
 | 
			
		||||
                "coerce": "absolute_path",
 | 
			
		||||
                "required": True,
 | 
			
		||||
                "path_exists": True,
 | 
			
		||||
            },
 | 
			
		||||
            "logging": {
 | 
			
		||||
                "type": "path",
 | 
			
		||||
                "coerce": "absolute_path",
 | 
			
		||||
 | 
			
		||||
@ -87,5 +87,6 @@ class SQLite(AuthOperations, BuildOperations, LogsOperations, PackageOperations,
 | 
			
		||||
 | 
			
		||||
        paths = configuration.repository_paths
 | 
			
		||||
 | 
			
		||||
        if configuration.getboolean("settings", "apply_migrations", fallback=True):
 | 
			
		||||
            self.with_connection(lambda connection: Migrations.migrate(connection, configuration))
 | 
			
		||||
        paths.chown(self.path)
 | 
			
		||||
 | 
			
		||||
@ -22,3 +22,14 @@ def test_init(database: SQLite, configuration: Configuration, mocker: MockerFixt
 | 
			
		||||
    migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
 | 
			
		||||
    database.init(configuration)
 | 
			
		||||
    migrate_schema_mock.assert_called_once_with(pytest.helpers.anyvar(int), configuration)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_init_skip_migration(database: SQLite, configuration: Configuration, mocker: MockerFixture) -> None:
 | 
			
		||||
    """
 | 
			
		||||
    must skip migrations if option is set
 | 
			
		||||
    """
 | 
			
		||||
    configuration.set_option("settings", "apply_migrations", "no")
 | 
			
		||||
    migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
 | 
			
		||||
 | 
			
		||||
    database.init(configuration)
 | 
			
		||||
    migrate_schema_mock.assert_not_called()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user