richan-fongdasen / turso-laravel

A Turso/LibSQL database driver for Laravel application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Migrate from sql dump file fails (Laravel squashed migration import)

BrandonDR opened this issue · comments

What happened?

I tried testing importing from an sql dump using Laravel's squash migrations feature.
https://laravel.com/docs/11.x/migrations#squashing-migrations

I get this error:

   Symfony\Component\Process\Exception\InvalidArgumentException 

  Command line is missing a value for parameter "LARAVEL_LOAD_DATABASE": sqlite3 "${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"

How to reproduce the bug

Create a database/schema/turso-schema.sql file with a simple CREATE TABLE statement.
Run artisan migrate:fresh with Turso as the database driver.

Output from php artisan migrate:fresh

  Dropping all tables ..................................................................................................................... 10s DONE

   INFO  Preparing database.  

  Creating migration table ........................................................................................................... 136.16ms DONE

   INFO  Loading stored database schemas.  

  database/schema/turso-schema.sql ................................................................................................... 148.70ms FAIL

   Symfony\Component\Process\Exception\InvalidArgumentException 

  Command line is missing a value for parameter "LARAVEL_LOAD_DATABASE": sqlite3 "${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"

  at vendor/symfony/process/Process.php:1585
    1581▕     private function replacePlaceholders(string $commandline, array $env): string
    1582▕     {
    1583▕         return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) {
    1584▕             if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) {
  ➜ 1585▕                 throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": ', $matches[1]).$commandline);
    1586▕             }
    1587▕ 
    1588▕             return $this->escapeArgument($env[$matches[1]]);
    1589▕         }, $commandline);

  1   [internal]:0
      Symfony\Component\Process\Process::Symfony\Component\Process\{closure}()
      +37 vendor frames 

  39  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

 ELIFECYCLE  Command failed with exit code 1.

Package Version

0.7.0

PHP Version

8.3

Laravel Version

11.6.0

Which operating systems does with happen with?

Linux

Notes

No response

Hi @BrandonDR ! Are you importing an existing SQLite database into a remote Turso database? It's best to use the Turso CLI for this.

Reference:
https://docs.turso.tech/cli/db/create#create-database-from-sqlite-file
https://docs.turso.tech/cli/db/create#create-database-from-sqlite-dump

Thanks @richan-fongdasen yeah that does work. I was just experimenting, I have a local sqlite database for unit tests. I was trying to import the dump in the same way. This is not a big deal I can work around it. Great work on this package by the way!

Glad to hear the CLI method works for you, @BrandonDR!

For testing, you can use database migrations and seeding like you normally would in a Laravel application. You can also use the Turso local development server for testing.

References:

I appreciate the feedback! It's great to hear how people are using this package. Let me know if you have any other questions.