Skip to content

Enhancement: add a migration config to a driver config #352

@euri10

Description

@euri10

Summary

i'd like a way to add a migration config after I created a driver config.
that would let me do something like the below:

from typing import Any, Self
from sqlspec import AsyncDatabaseConfig, SQLSpec, SyncDatabaseConfig
from sqlspec.adapters.sqlite import SqliteConfig

class KS:
    def __init__(self, spec: SQLSpec, config: SyncDatabaseConfig[Any, Any, Any] | AsyncDatabaseConfig[Any, Any, Any],
                 ) -> None:
        self.spec = spec
        self.config = config


    @classmethod
    def create(cls, spec: SQLSpec, config: SyncDatabaseConfig[Any, Any, Any, ])-> Self:
        self = cls(spec=spec, config=config, )
        # here i'd like something like config.add_migration_coonfig(toto)
        current = config.get_current_migration()
        if not current:
            try:
                config.migrate_up(echo=True)
            except Exception as e:
                print(f"Migration failed: {e}")
                raise e 
        return self



spec = SQLSpec()
config = SqliteConfig(connection_config={"database": "tt.db"},)
ks = KS.create(spec, config)

weirdly enough the above raises with a sqlspec.exceptions.SQLFileNotFoundError: SQL file 'migrations/0001_init.sql' not found but I'm positive the file exists.

also if I add a migration_config to the sqlite config above, then it finds there is one migration, and it fails because the file is not found, how can it not find the file if it detected it in the first place ?

Image

Basic Example

No response

Drawbacks and Impact

No response

Unresolved questions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions