承接 swouters/sql-migrations-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

swouters/sql-migrations-bundle

最新稳定版本:1.2.1

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 6.4
  • PostgreSQL using the public schema (not compatible with other databases for now)

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

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

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

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:

// config/bundles.php

return [
    // ...
    SWouters\SqlMigrationsBundle\SqlMigrationsBundle::class => ['all' => true],
];

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

统计信息

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

GitHub 信息

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

其他信息

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