PHPackages                             inovxapp/dbstate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. inovxapp/dbstate

ActiveLibrary[Database &amp; ORM](/categories/database)

inovxapp/dbstate
================

Declarative database schema-as-code for Laravel.

v0.0.1(5mo ago)01BSL-1.1PHPPHP ^8.2|^8.3|^8.4

Since Dec 17Pushed 5mo agoCompare

[ Source](https://github.com/inovxapp/dbstate)[ Packagist](https://packagist.org/packages/inovxapp/dbstate)[ Docs](https://github.com/inovxapp/dbstate)[ RSS](/packages/inovxapp-dbstate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

DBState — Declarative database schema for Laravel
=================================================

[](#dbstate--declarative-database-schema-for-laravel)

**DBState is a Laravel tool for managing database schemas using a declarative, schema-as-code approach.**

Describe your tables using simple, versionable `.dbstate.php` files, then DBState synchronizes your database schema — no manual migrations required.

Inspired by the declarative approaches of Ansible and Docker Compose: you declare the desired state, and DBState applies the diff.

---

🚀 Features
----------

[](#-features)

- **Declarative schema** : describe the desired structure and DBState applies the diff.
- **Automatic table diffs** (add, delete, modify columns).
- **No SQL required**.

- **Custom root folder** via `DBSTATE_FOLDER`.
- **Schema import** : automatically generate .dbstate.php files from your existing database.

---

📦 Installation
--------------

[](#-installation)

```
composer require inovxapp/dbstate
```

Publish config and base structure (honoring `DBSTATE_FOLDER` if set):

```
php artisan vendor:publish --tag=dbstate
# or publish separated
php artisan vendor:publish --tag=dbstate-config
php artisan vendor:publish --tag=dbstate-database
```

Set `DBSTATE_FOLDER` in your `.env` before publishing if you want to customize the destination folder for all generated files (see below).

---

⚙️ Configuration
----------------

[](#️-configuration)

A config file is published to:

```
config/dbstate.php

```

---

📡 Custom Root Folder
--------------------

[](#-custom-root-folder)

Set a custom root folder (optional) in .env files using :

```
DBSTATE_FOLDER=dbstate

```

This lets you place DBState files anywhere in your project.

---

📁 Folder Structure
------------------

[](#-folder-structure)

Default structure :

```
config/dbstate.php

database/dbstate/
 ├── actions/
 ├── backups/
 ├── import/
 └── tables/
     └── *.dbstate.php

```

The published configuration file lives in `config/dbstate.php`.

With `DBSTATE_FOLDER=dbstate`:

```
dbstate/
 ├── config/dbstate.php
 └── database/
     ├── actions/
     ├── backups/
     ├── import/
     └── tables/
        └── *.dbstate.php

```

---

✨ Quick Start
-------------

[](#-quick-start)

- Start DBState in terminal:

```
php artisan dbstate
```

Need a quieter diff or to include package tables?

```
php artisan dbstate --compact          # compact output
php artisan dbstate --with-package-tables    # include tables listed in packages_tables when running CheckDiff
```

- Import your existing tables:

```
4/7 - ImportMyDB - Create all DBState table from your DB
```

This will automatically generate .dbstate.php files from your existing database in the `/import` folder. Then you can decide to move automatically all this file in the `/tables` folder

- Create a table definition:

```
/tables/posts.dbstate.php
