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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With