1 回答

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
我做的和我上面勾勒的完全一樣,而且效果很好。對(duì)于上下文,我有一組用于遷移腳本的元數(shù)據(jù):
"SELECT * FROM migration_versions"
┌────────────────┐
│ version │
├────────────────┤
│ 20161112122228 │
│ 20161113143631 │
│ 20161122223420 │
│ 20161124162611 │
│ 20161128151448 │
│ 20161207194257 │
│ 20161208114104 │
│ 20161208114105 │
│ 20170123074229 │
│ 20170125081729 │
│ 20170130080734 │
│ 20170130080820 │
│ 20170131082751 │
│ 20170201074705 │
│ 20170208092040 │
│ 20170208092917 │
│ 20170208103930 │
│ 20170608042313 │
│ 20170628044258 │
│ 20170930061118 │
└────────────────┘
這意味著我還會(huì)有一組相應(yīng)的文件app/DoctrineMigrations/,稱為app/DoctrineMigrations/Version20170930061118.php. 只有最后一個(gè)文件以實(shí)際內(nèi)容結(jié)束,其余的將是空的假人。
我的更改的 Git 日志
創(chuàng)建一個(gè)虛擬模板來(lái)替換現(xiàn)有遷移的內(nèi)容
在某些時(shí)候,現(xiàn)有的遷移已經(jīng)停止工作。這是在 2020 年 3 月 1 日左右發(fā)現(xiàn)的。
這意味著不可能從新的源代碼開(kāi)始開(kāi)發(fā),使用教義:遷移:遷移命令,因?yàn)樗茉缇褪×恕?/p>
同時(shí),現(xiàn)有數(shù)據(jù)庫(kù)包含有關(guān)過(guò)去執(zhí)行了哪些遷移的元數(shù)據(jù),因此任何修復(fù)都需要向遷移包發(fā)出信號(hào),表明這些遷移已經(jīng)/已經(jīng)執(zhí)行。
建議的解決方法是創(chuàng)建簡(jiǎn)單的“標(biāo)記類”,它只是滿足發(fā)出遷移已經(jīng)完成/存在的信號(hào)的需要,然后用一個(gè)腳本替換最后一個(gè)遷移類的內(nèi)容,該腳本只是創(chuàng)建一個(gè)與當(dāng)前狀態(tài)匹配的模式生產(chǎn)數(shù)據(jù)庫(kù)是。
這是第 1 步。
將所有遷移腳本內(nèi)容替換為空內(nèi)容
這是修復(fù)中的第 2 步。基本上為 app/DoctrineMigrations/*.php 中的每個(gè)文件執(zhí)行一個(gè)循環(huán),并用虛擬模板替換它。這是完整的腳本
$ git show 773ccebee20425d7025152b338282f0a0034556f:app/DoctrineMigrations/create-dummy-migrations.sh
#!/bin/bash
for file in Version*.php; do
CLASS=$(basename $file .php)
sed -e "s/CLASSNAME/$CLASS/" template.php > $file
done
這是完整的模板
git show 773ccebee20425d7025152b338282f0a0034556f:app/DoctrineMigrations/template.php
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Dummy migration to fix faulty migration scripts issue
* discovered in March 2020.
*/
class CLASSNAME extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->addSql('COMMENT ON table migration_versions IS \'migrations from 2016-2017 are stubs\'');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}
刪除助手
從 prod 轉(zhuǎn)儲(chǔ)模式
使用腳本清理架構(gòu)
grep -v -- '--' production-schema-2020.sql \
| awk 1 ORS=' ' \
| sed -r -e 's/;\s+/; /g' > cleaned.sql
從 SQL 腳本生成 Doctrine PHP 語(yǔ)句
腳本:sed -e "s/^(.*);/\$this->addSql('\1');/" cleaned.sql > cleaned-sql-to-php-statements.txt
將模式語(yǔ)句移動(dòng)到上次遷移 中基本上將內(nèi)容從復(fù)制粘貼cleaned-sql-to-php-statements.txt到
刪除臨時(shí)文件
對(duì)生成的 PHP SQL 語(yǔ)句的小調(diào)整和清理
- 1 回答
- 0 關(guān)注
- 105 瀏覽
添加回答
舉報(bào)