Skip to content

Commit b941c6f

Browse files
committed
feat: update schema file docs
1 parent decc88f commit b941c6f

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

src/docs/database/files.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ columns:
135135

136136
This example will add a `created_at` column to the `posts` table with the current timestamp as the default value.
137137

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+
138150
## Schema columns
139151

140152
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:
228240

229241
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.
230242

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:
292+
293+
```bash:no-line-numbers
294+
php leaf db:drop users
295+
```
232296

233297
## Seeding your database
234298

src/docs/database/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Leaf MVC configures everything for you out of the box, so you just need to defin
6666
<div
6767
class="sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
6868
>
69-
<p class="font-semibold text-sm text-rose-100 text-shadow mb-4">
69+
<p class="font-semibold text-sm text-rose-100 text-shadow mb-4 !mt-0">
7070
Schema files allow you to define the structure of your database tables in a simple and intuitive way.
7171
</p>
7272
<Button
@@ -95,8 +95,8 @@ Leaf MVC configures everything for you out of the box, so you just need to defin
9595
<div
9696
class="sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
9797
>
98-
<p class="font-semibold text-sm text-blue-100 text-shadow mb-4">
99-
Models are a powerful way to interact with your database using an object-oriented approach.
98+
<p class="font-semibold text-sm text-blue-100 text-shadow mb-4 !mt-0">
99+
Models are a powerful way to interact with your db using an object-oriented approach.
100100
</p>
101101
<Button
102102
as="a"
@@ -124,8 +124,8 @@ Leaf MVC configures everything for you out of the box, so you just need to defin
124124
<div
125125
class="sm:max-w-sm sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
126126
>
127-
<p class="font-semibold text-sm text-amber-100 text-shadow mb-4">
128-
You can use Leaf DB to build and run queries that don't fit into a model, without any config.
127+
<p class="font-semibold text-sm text-amber-100 text-shadow mb-4 !mt-0">
128+
You can use Leaf DB to build queries that don't fit into a model, without any config.
129129
</p>
130130
<Button
131131
as="a"

0 commit comments

Comments
 (0)