sarelvdwalt/db-archive-bundle

使用不同策略归档数据库表的工具包

dev-master 2015-11-02 05:58 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:11:09 UTC


README

用途

本工具包的目的是提供一个通用的Symfony2控制台命令,用于归档数据库表。一般思路是提供表名和归档策略。

假设有一个名为"stuff"的表,里面有1亿条记录。假设"stuff"表有一个名为created_at的字段,这是一个日期时间字段,例如MySQL(或任何您的基础数据库)。

当执行命令php app/console archive:generic stuff时,它将遍历"stuff"表,并将值归档到以"z"开头,以"created_at"列的"Ym"值结尾的表中。

例如,一个拥有"created_at"为"2014-03-11 23:54:22"的记录将被归档到名为zstuff201403的表中。一个拥有"created_at"为"2014-02-28 08:23:00"的记录将被归档到zstuff201402表中 - 注意区别在于末尾的月份。

背后的逻辑是,以"z"开头的表将在您的表列表末尾,这样做的目的是避免 cluttering 您的主要数据库视图。

用法

Usage:
 archive:generic [--days="..."] [--strategy-z-tables[="..."]] [--strategy-source-field="..."] [--batch-size[="..."]]
 [--source-entity-manager="..."] [--destination-entity-manager="..."] table_name

Arguments:
 table_name                    The name of the source table to archive

Options:
 --days                        Defines how many days in the past to start archive.
                               Example, 14 would archive data older than 14 days (default: 90)
 --strategy-z-tables           Strategy is to create tables of the same name, in format zTableNameYm
                               (ex zclients201403. (default: "Ym")
 --strategy-source-field       Field to base the strategy on. For the YYYYMM strategy, this has to be
                               a date field (default: "created_at")
 --batch-size                  Size of each batch. It is important not to choose too big or small a batch.
                               Big batches will cause memory problems, small ones will decrease the
                               speed of archiving. (default: 100)
 --source-entity-manager       Source Entity Manager to archive from (default: "default")
 --destination-entity-manager  Destination Entity Manager to archive to. If none is provided,
                               the same as --source-entity-manager will be used. (default: "default">

报告问题或功能请求

请在Github问题跟踪器中提交问题和功能请求。