Perl 如何使用add_trigger方法在“DBIx::Class”的帮助下在数据库中创建触发器?
我想将触发器添加到我的数据库中。我使用Perl 如何使用add_trigger方法在“DBIx::Class”的帮助下在数据库中创建触发器?,perl,dbix-class,Perl,Dbix Class,我想将触发器添加到我的数据库中。我使用DBIx::Class并遵循以下示例:,。 我的代码是: package App::Schema; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_namespaces(); sub sqlt_deploy_hook { my ($self, $schema) = @_; $schema->add_trigger( name => 'foo' ); } 一, 但我得
DBIx::Class
并遵循以下示例:,。我的代码是:
package App::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_namespaces();
sub sqlt_deploy_hook {
my ($self, $schema) = @_;
$schema->add_trigger( name => 'foo' );
}
一,
但我得到了这个错误:
Failed to translate to YAML: translate: Error with producer 'SQL::Translator::Producer::YAML': Can't call method "name" on an undefined value at /home/kes/work/projects/x/app/local/lib/perl5/SQL/Translator/Schema/Trigger.pm line 198
当按照dbic迁移的要求使用所有环境变量运行命令时
:
dbic-migration --force --schema_class App::Schema --database PostgreSQL -Ilib prepare
这让我想到了什么地方
我错过了什么?如何修复此错误
UPD
即使我添加了所有参数,也会出现错误:
Failed to translate to YAML: translate: Error with parser 'SQL::Translator::Parser::DBIx::Class': Table named users doesn't exist at /home/kes/work/projects/x/app/local/lib/perl5/SQL/Translator/Schema/Trigger.pm line 54
目标线:
my $table = $args->{schema}->get_table($arg)
or die "Table named $arg doesn't exist";
修改代码:
sub sqlt_deploy_hook {
my ($self, $schema) = @_;
warn "TABLES: " ,$schema->get_tables ,"\n";
$schema->add_trigger(()
,name => 'foo'
,perform_action_when => 'after'
,database_events => 'insert'
,on_table => 'users'
,action => 'text'
,scope => 'row'
);
}
此代码将生成下一个警告:
TABLES: users
TABLES: dbix_class_deploymenthandler_versions
但DB目前只有一个表。我希望它至少应该产生:
TABLES: users dbix_class_deploymenthandler_versions
如何在
DB
中创建触发器?可能存在以下问题:
它最初设计为预期要部署的表的结果类名和$sqlt_表实例
作为解决方法,在添加触发器之前添加下一行代码
:
return unless grep $_ eq 'users', $schema->get_tables;
但推荐的方法是手动创建部署/升级/降级.sql
文件