You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/database/files.md
+65-1Lines changed: 65 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,6 +135,18 @@ columns:
135
135
136
136
This example will add a `created_at` column to the `posts` table with the current timestamp as the default value.
137
137
138
+
## Multiple DB connections <Badge>New</Badge>
139
+
140
+
Leaf MVC supports multiple database connections via the `database.php` configuration file. By default, Leaf uses the `default` connection for all database operations. However, if you want to use a different connection for a specific table, you can specify the connection in the schema file using the `connection` key. Here's an example:
141
+
142
+
```yml:no-line-numbers [posts.yml]
143
+
connection: postsDbConnection
144
+
145
+
columns:
146
+
title: string
147
+
body: text
148
+
```
149
+
138
150
## Schema columns
139
151
140
152
In a schema file, you can define the columns of your table under the `columns` key. The key is the column name and the value is the type of column or an array of properties for the column:
@@ -228,7 +240,59 @@ columns:
228
240
229
241
This example adds a new column `is_super_admin` to the `users` table. When you run `php leaf db:migrate`, Leaf will compare it to the previous version of the file, find the differences and automatically create the `is_super_admin` column for you in your database. You don't need to worry about writing migration files or keeping track of changes manually.
230
242
231
-
And when you need to roll back? Simply run `php leaf db:rollback`.
243
+
## Reverting changes
244
+
245
+
The schema system automatically tracks changes, so you can easily roll back to a previous state. Just run:
246
+
247
+
```bash:no-line-numbers
248
+
php leaf db:rollback
249
+
```
250
+
251
+
This will revert the last set of changes made to your database. If you want to roll back a specific table instead of all tables, you can pass the table name as an argument to the `db:rollback` command:
252
+
253
+
```bash:no-line-numbers
254
+
php leaf db:rollback users
255
+
```
256
+
257
+
Rolling back is like hitting "undo" on your database: It reverts the last migration, letting you step back through changes one at a time. Sometimes, you might need to revert multiple steps at a time, so you can use the `--steps` option to specify how many steps to roll back:
258
+
259
+
```bash:no-line-numbers
260
+
php leaf db:rollback --steps=3
261
+
```
262
+
263
+
This command will roll back the last three migrations made to your database.
264
+
265
+
------
266
+
267
+
### Resetting tables
268
+
269
+
While rolling back is great for undoing recent changes, there are times when you might want to reset your entire database to a clean state. For those situations, Leaf provides the `db:reset` command. This command will roll back all migrations and then re-apply them, effectively giving you a fresh start. You can run it like this:
270
+
271
+
```bash:no-line-numbers
272
+
php leaf db:reset
273
+
```
274
+
275
+
You can also reset a specific table by passing the table name as an argument:
276
+
277
+
```bash:no-line-numbers
278
+
php leaf db:reset users
279
+
```
280
+
281
+
------
282
+
283
+
### Dropping tables <Badge>New</Badge>
284
+
285
+
Finally, if you want to completely remove all tables from your database, you can use the `db:drop` command, meaning all your data and tables will be deleted. Use this command with caution:
286
+
287
+
```bash:no-line-numbers
288
+
php leaf db:drop
289
+
```
290
+
291
+
You can also drop a specific table by passing the table name as an argument:
0 commit comments