Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel sqlite relative path

Tags:

sqlite

laravel

I want to deploy my application in multiple pc's and it's using sqlite for db. Is there any way to set a relative path instead of an absolute one in my env file? Is there any alternative to sqlite to have portable database?

Example is there anyway to use something like this:

DB_DATABASE=${ variable/to/database/folder }/database.sqlite

Instead of:

DB_DATABASE=C:\wamp64\www\JUICE\projects\my-project\database\database.sqlite
like image 734
Luca Rossi Avatar asked Sep 04 '19 10:09

Luca Rossi


Video Answer


2 Answers

First step comment out DB_DATABASE in .env:

#DB_DATABASE=homestead

Second, check you have this in config/database.php, it's the code that ships with laravel:

'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

And you have your database path relative to your application root and changing with the application directory because you rely on the path helper database_path().

I can't give you any alternative, I use sqlite for local development with satisfaction.

like image 142
dparoli Avatar answered Oct 23 '22 21:10

dparoli


The default database configuration already includes a relative path to the database file for sqlite

'database' => env('DB_DATABASE', database_path('database.sqlite')),

Now to use your .env variable to rename the file but keep a relative path you can do this .env

DB_DATABASE=different-name.sqlite

config/database.php

'database' => database_path(env('DB_DATABASE')),

Is there any alternative to sqlite to have portable database?

You can export any database like MySQL as a .sql file populated with data and push it to your git repo

Here's an example of doing so with Redis using a Python Script

# dump database 0
./redisdl.py > dump.json
./redisdl.py -o dump.json

# load into database 0
./redisdl.py -l < dump.json
./redisdl.py -l dump.json
like image 31
Salim Djerbouh Avatar answered Oct 23 '22 23:10

Salim Djerbouh