Download the PHP package swouters/sql-migrations-bundle without Composer
On this page you can find all versions of the php package swouters/sql-migrations-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download swouters/sql-migrations-bundle
More information about swouters/sql-migrations-bundle
Files in swouters/sql-migrations-bundle
Package sql-migrations-bundle
Short Description Allow symfony database versioning using SQL plain files.
License
Informations about the package sql-migrations-bundle
SQL Migrations Bundle
A Symfony bundle for database versioning, using only plain SQL files.
Allows maintaining a database schema without using the Doctrine ORM entities system.
Installation
Prerequisites:
- PHP 8.3
- Symfony 6.4
- PostgreSQL using the public schema (not compatible with other databases for now)
- Doctrine DBAL 4.* configured
Step 0: Prepare your project
If you start with a fresh Symfony skeleton, you will need Doctrine to install the bundle.
Install the ORM-pack (it's the only way to have \Connection services properly configured):
We don't need the ORM parts; you can clean up your project:
- remove
src/Entity
andsrc/Repository
folders - in the
config/packages/doctrine.yaml
, keep only thedoctrine.dbal
parts
Step 1: Download the Bundle
Open a command console, enter your project directory, and execute the following command to download the latest stable version of this bundle:
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
Usage
Step 1: Put your .sql migration files in a migrations
directory at the root of your project
The order of the files is important, the bundle will execute them in the order of their names.
I recommend adding the date in the filename, like YYYYMMDD_[feature].sql
, to keep track of the order.
There is no down migration system.
Step 2: Run the command to apply the migrations
That command will execute all the SQL files in the migrations
directory that have not been executed yet.
The --dry-run
option will only display the SQL queries that will be executed. Remove the option to execute the queries.
You can add the --drop-database
option to drop the database (the public schema) before applying the migrations (useful for local/dev environment).
That command will use an internal table _migrations
in the database to keep track of the applied migrations. You can change the name of the table by setting the SQL_MIGRATIONS_TABLE
environment variable.
Development
Clone the repository :
Run tests locally
With Docker
The docker stack includes the PHP runtime and the PostgreSQL database.
Without Docker
Prequisites:
- Php 8.3 / Composer
- A running PostgreSQL database
- A dedicated database for tests
Create a .env.test.local
file and adapt the DATABASE_URL
variable to your configuration:
Run tests:
All versions of sql-migrations-bundle with dependencies
symfony/framework-bundle Version 6.4.*
symfony/console Version 6.4.*
doctrine/dbal Version ^4.0