如何使用 dbicdump 仅转储特定 table

How to use the dbicdump to only dump specific table

我只需要从我的数据库中转储特定的 tables 这样这些 特定的 tables (3 tables 确切地说是 200 tables) 现在将由 DBIx::Class::Schema 实施。

这是来自文档 (https://metacpan.org/pod/dbicdump) 的命令:

dbicdump -o dump_directory=./lib   -o components='["InflateColumn::DateTime"]'   -o preserve_case=1   MyApp::Schema dbi:mysql:database=database_name user pass;

我尝试在 database_name 之后附加 table 名称,但没有成功,它仍然会转储指定数据库中的所有 table。需要帮忙。我在文档中找不到任何内容。

同样是题外话问题:

这些是什么意思? -o components='["InflateColumn::DateTime"]' -o preserve_case=1 我在文档中也找不到他们的解释。

谢谢

您可以将 the option constraint 传递给基础 DBIx::Class::Schema::Loader 实例,以便它只选择某些表。文档对此有点含糊。

These can be specified either as a regex (preferrably on the qr// form), or as an arrayref of arrayrefs. Regexes are matched against the (unqualified) table name, while arrayrefs are matched according to "moniker_parts".

For example:

db_schema => [qw(some_schema other_schema)],
moniker_parts => [qw(schema name)],
constraint => [
    [ qr/\Asome_schema\z/ => qr/\A(?:foo|bar)\z/ ],
    [ qr/\Aother_schema\z/ => qr/\Abaz\z/ ],
],

In this case only the tables foo and bar in some_schema and baz in other_schema will be dumped.

所以您需要传递给 dbicdump 的内容看起来像这样。

dbicdump \
  -o dump_directory=./lib \
  -o components='["InflateColumn::DateTime"]' \
  -o preserve_case=1 \
  -o constraint='qr/^(?:foo|bar|baz)$/' \
   MyApp::Schema dbi:mysql:database=database_name user pass;

那只会给你表 foobarbaz。如果只有一个模式,您需要不带数组引用的引用正则表达式,并且您不想使用手动预设的名字对象(这是用于生成的模式中的表的名称 class)。