swouters/sql-migrations-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

swouters/sql-migrations-bundle

Composer 安装命令:

composer require swouters/sql-migrations-bundle

包简介

Allow symfony database versioning using SQL plain files.

README 文档

README

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.4
  • Symfony 7.4.*
  • PostgreSQL using the public schema (not compatible with other databases for now)

Step 1: 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):

composer require orm
composer remove doctrine/doctrine-migrations-bundle

We don't need the ORM parts; you can clean up your project:

  • remove src/Entity and src/Repository folders
  • in the config/packages/doctrine.yaml, keep only the doctrine.dbal parts

Step 2: 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:

composer require swouters/sql-migrations-bundle:~2.1

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.

php bin/console sql-migrations:execute --dry-run

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.

Other commands

Mark a migration as applied without executing it:

php bin/console sql-migrations:mark-applied ./migrations/<migration_filename.sql>

Reset the _migration table and mark all migrations as applied without executing them:

php bin/console sql-migrations:mark-applied --all

Development

Clone the repository :

git clone https://github.com/Doelia/sql-migrations-bundle.git

Run tests locally

With Docker

The docker stack includes the PHP runtime and the PostgreSQL database.

.cloud/test.sh

Without Docker

Prequisites:

  • Php 8.4 / 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:

DATABASE_URL=pgsql://user:password@host:port/database

Run tests:

composer update
vendor/bin/phpunit

统计信息

  • 总下载量: 3.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-04-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固