【问题标题】:How to use Minion Task Migrations for Database Migrations如何使用 Minion 任务迁移进行数据库迁移
【发布时间】:2013-05-31 13:11:20
【问题描述】:

我正在运行 Kohana 3.3 并希望将数据库迁移添加到我的项目中。

我添加了以下模具https://github.com/kohana-minion/tasks-migrations,但不知道如何让它工作。

我可以看到运行./minion migrations:new --help 的帮助文件,但我不明白group 需要什么值。从文档中说:

--group=group_name

 This is a required config option, use it specify in which group the
 migration should be stored. Migrations are stored in a `migrations`
 directory followed by the group name specified. By default, the `migrations`
 directory is created in `APPPATH` but that can be changed with `--location`

--location=modules/auth

 Specified the path of the migration (without the `migrations` directory).
 This value is defaulted to `APPPATH`

 # The migration will be created in `modules/myapp/migrations/myapp/`
 --group=myapp --location=modules/myapp

--description="Description of migration here"

 This is an arbitrary description of the migration, used to build the
 filename.  It is required but can be changed manually later on without
 affecting the integrity of the migration.

我一直在寻找示例,但还没有找到。我有一个现有的数据库,所以我想从中获取模式作为我的基础,然后运行进一步的迁移。 tasks-migrations 模块是这样工作的吗?

【问题讨论】:

    标签: database kohana kohana-3 database-migration


    【解决方案1】:

    group 方法用来告诉你它是什么类型的迁移。如果是核心应用程序的迁移,那么core 组将是合适的。

    但也许您为自己的应用程序构建了一个模块,该模块有自己的表,因此也有自己的迁移。因此最好使用module_name 组。

    这样,您可以将迁移拆分为更合适的部分,并且能够轻松地仅检查模块的迁移,而无需搜索所有其他迁移。

    进行新的迁移

    ./minion migrations:new --group=core
    

    运行迁移

    ./minion migrations:run
    

    PS:不要忘记将迁移表添加到数据库中

    【讨论】:

    • 谢谢,顺便说一句,它在运行第一次迁移时创建了迁移表。
    • 顺便说一句,确保在创建表时,当您使用 innodb 时,您也将其更改为 innodb。如果您使用快速复制方法,混合表类型可能会导致数据库备份问题。
    【解决方案2】:

    组是迁移版本号,例如

    ./minion migrations:new --group=0-1

    使用 up 和 down 方法在 application/migrations/0.1 中创建了一个文件夹和迁移文件。

    【讨论】:

      猜你喜欢
      • 2016-10-15
      • 2017-02-10
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      相关资源
      最近更新 更多