Skip to content

Commit f2ab159

Browse files
committed
improve databases
1 parent 475c9b0 commit f2ab159

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

resources/views/docs/1/digging-deeper/databases.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,63 @@ keeping download & install size small.
3131

3232
You do not need to do anything special to configure your application to use SQLite. NativePHP will automatically:
3333
- Switch to using SQLite when building your application
34-
- Create a database file for you in the `storage` directory on the user's system
34+
- Create a database file for you in the `appdata` directory on the user's system
3535
- Configure your application to use that database file
36-
- Run your migrations each time your app starts if needed
36+
- Run your migrations each time your app starts, as needed
37+
38+
## Development
39+
40+
Remember that in [development](/docs/getting-started/development) your application's database is always going to be
41+
the SQLite database created in the `appdata` folder for your application.
42+
43+
This means that even if you've got different config in your `.env` file, your application will not be connecting to any
44+
other database when it is running within the Electron/Tauri environment.
3745

3846
## Migrations
3947

4048
When writing migrations, you need to consider any special recommendations for working with SQLite. For example,
4149
SQLite disables foreign key constraints by default. If your application relies upon foreign key constraints,
42-
[you need to enable SQLite support for them](https://laravel.com/docs/10.x/database#configuration) before
50+
[you need to enable SQLite support for them](https://laravel.com/docs/database#configuration) before
4351
writing your migrations.
4452

4553
**It's important to test your migrations before releasing updates!** You don't want to accidentally delete your user's
4654
data when they update your app.
4755

56+
### Running migrations
57+
58+
NativePHP will attempt to migrate your database on each boot-up.
59+
60+
You may also wish to manually migrate it during development, either while the application is already running or without
61+
booting the application.
62+
63+
You can do this with the `native:migrate` command:
64+
65+
```shell
66+
php artisan native:migrate
67+
```
68+
69+
This command uses the exact same signature as the Laravel `migrate` command, so everything you're used to there can be
70+
used here.
71+
72+
### Refreshing your app database
73+
74+
You can completely refresh your app database using the `native:migrate fresh` command:
75+
76+
```shell
77+
php artisan native:migrate fresh
78+
```
79+
80+
**This is a destructive action that will delete all data in your database.**
81+
82+
## Seeding
83+
84+
When developing, it's especially useful to seed your database with sample data. If you've set up
85+
[Database Seeders](https://laravel.com/docs/seeding), you can run these using the `native:db:seed` command:
86+
87+
```shell
88+
php artisan native:db:seed
89+
```
90+
4891
## When not to use a database
4992

5093
If you're only storing small amounts of very simple metadata or working files, you may not need a database at all.

0 commit comments

Comments
 (0)