Skip to content

Initialization of schema_migrations does not work when using sqlite #168

@svetlyak40wt

Description

@svetlyak40wt

A minimal example to reproduce:

CL-USER> (let ((mito:*connection* (dbi:connect :sqlite3 :database-name #P"/tmp/myapp.db")))
              (unwind-protect
                   (mito.migration:migrate #P"/tmp/db/")
                (dbi:disconnect mito:*connection*)))

When executed in REPL it signals the error:

DB Error: near "?": syntax error (Code: ERROR)
   [Condition of type DBI.ERROR:DBI-PROGRAMMING-ERROR]

Restarts:
 0: [RETRY] Retry SLY mREPL evaluation request.
 1: [*ABORT] Return to SLY's top level.
 2: [ABORT] abort thread (#<THREAD tid=55641 "sly-channel-1-mrepl-remote-1" RUNNING {1000BB0003}>)

Backtrace:
 0: ((:METHOD DBI.DRIVER:PREPARE (DBD.SQLITE3:DBD-SQLITE3-CONNECTION STRING)) #<DBD.SQLITE3:DBD-SQLITE3-CONNECTION {1002B4F4B3}> "CREATE TABLE IF NOT EXISTS \"schema_migrations$
      Locals:
        #:.DEFAULTING-TEMP. = T
        DBD.SQLITE3::CONN = #<DBD.SQLITE3:DBD-SQLITE3-CONNECTION {1002B4F4B3}>
        DBD.SQLITE3::CONN-HANDLE = #<SQLITE:SQLITE-HANDLE {1002B4F413}>
        DBD.SQLITE3::E = #<SQLITE:SQLITE-ERROR "Could not prepare an sqlite statement." {1002F0DA83}>
        DBD.SQLITE3::SQL = "CREATE TABLE IF NOT EXISTS \"schema_migrations\" (\n    \"version\" BIGINT PRIMARY KEY,\n    \"applied_at\" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMES$
        DBD.SQLITE3::STORE = T
 1: (MITO.UTIL::CALL-WITH-PREPARED-QUERY #<DBD.SQLITE3:DBD-SQLITE3-CONNECTION {1002B4F4B3}> "CREATE TABLE IF NOT EXISTS \"schema_migrations\" ( ..)
 2: ((:METHOD MITO.DB:EXECUTE-SQL (STRING)) "CREATE TABLE IF NOT EXISTS \"schema_migrations\" ( ..) [fast-method]
      Locals:
        MITO.DB::BINDS = (0)
        MITO.DB::SQL = "CREATE TABLE IF NOT EXISTS \"schema_migrations\" (\n    \"version\" BIGINT PRIMARY KEY,\n    \"applied_at\" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP$
 3: (MITO.MIGRATION.VERSIONS::INITIALIZE-MIGRATIONS-TABLE)
 4: (MITO.MIGRATION.VERSIONS:CURRENT-MIGRATION-VERSION)
 5: (MITO.MIGRATION.VERSIONS:MIGRATE #P"/tmp/db/" :DRY-RUN NIL :FORCE NIL)

But if I create table manually:

CREATE TABLE IF NOT EXISTS "schema_migrations" (
    "version" BIGINT PRIMARY KEY,
    "applied_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "dirty" BOOLEAN NOT NULL DEFAULT 0
);

then I'm able to generate and apply migrations and mito:create-dao works as well.

I'm using Mito from Ultralisp.org, version built at 2024-11-18 04:32:46, which corresponds to this commit (latest for the moment when this issue was created).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions