PHPackages                             dbykov/schemasync - 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. dbykov/schemasync

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

dbykov/schemasync
=================

SchemaSync: generate SQL migrations from DTOs (MySQL/Postgres) and warn about destructive changes.

v0.0.2(8mo ago)02MITPHPPHP &gt;=8.1

Since Sep 17Pushed 8mo agoCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

SchemaSync — DTO → SQL schema/migrations (MySQL/PostgreSQL)
===========================================================

[](#schemasync--dto--sql-schemamigrations-mysqlpostgresql)

English | Русский (ниже)

English

Overview SchemaSync takes your PHP DTOs (typed properties, PHP ≥ 8.1) and turns them into:

- CREATE TABLE SQL for MySQL or PostgreSQL
- ALTER TABLE migration steps to bring an existing DB schema in sync with a DTO
- A diff report with risk levels (INFO/WARNING/DANGER) highlighting potentially destructive changes

It also provides a CLI (bin/schemasync) and a programmatic API.

Key features (MVP)

- Input sources: PHP DTO classes with typed properties and optional PHP 8.1 attributes, or sample array/JSON (basic support).
- SQL generation:
    - CREATE TABLE for a new DTO.
    - ALTER TABLE steps for schema diff.
- DB verification: compares against a live database (information\_schema) and prints diff + risk warnings.
- CLI:
    - generate --dialect=mysql|pgsql — print CREATE TABLE.
    - diff --dialect=... --dsn=... \[--user=\] \[--pass=\] \[--table=\] — print ALTER steps and risk report.
- Attributes support on properties, e.g. name, length, precision/scale, nullable, default.

Requirements

- PHP &gt;= 8.1
- PDO extension and a MySQL or PostgreSQL database (for diff against live DB)
- Composer (for autoload)

Installation

- As a project dependency or a local package:
- Install dependencies:

```
# install vendor deps
composer install
```

- Make CLI executable:

```
chmod +x bin/schemasync
```

Quick start

1. Define a DTO

```
