Skip to content

RANDOM ROWID is not supported by sqlite3-parser #67

@devpikachu

Description

@devpikachu

This bug was observed whilst running migrations via geni, which depends on this crate.

Given the following SQL statement:

CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    uid TEXT UNIQUE NOT NULL,
    display_name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL,
    password BLOB NOT NULL,
    salt BLOB NOT NULL,
    created_at TEXT NOT NULL,
    created_by INTEGER,
    updated_at TEXT,
    updated_by INTEGER,
    FOREIGN KEY (created_by) REFERENCES users(id),
    FOREIGN KEY (updated_by) REFERENCES users(id)
) RANDOM ROWID;

The thread panics with the following error:

🚀 RUST_BACKTRACE=1 ./geni.sh up
12:43:45 [INFO] Running migration 1706354475
thread 'main' panicked at /tmp/cargo-installmSZF7O/release/build/sqlite3-parser-98bd5a2c8e53e2a9/out/parse.rs:576:13:
internal error: entered unreachable code
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:127:5
   3: sqlite3_parser::parser::parse::yyParser::yy_reduce
   4: sqlite3_parser::parser::parse::yyParser::sqlite3Parser
   5: <sqlite3_parser::lexer::sql::Parser as fallible_iterator::FallibleIterator>::next
   6: fallible_iterator::FallibleIterator::fold
   7: libsql_client::local::Client::execute
   8: <geni::database_drivers::sqlite::SqliteDriver as geni::database_drivers::DatabaseDriver>::execute::{{closure}}
   9: geni::main::{{closure}}
  10: tokio::runtime::park::CachedParkThread::block_on
  11: geni::main

This corrupts the database file and a full wipe is needed. Removing the RANDOM ROWID statement makes the migrations occur correctly and the schema is as-defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions