-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4094 from portabilis/issue-4083
Cria triggers para auditar tabelas da banco;
- Loading branch information
Showing
12 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...car/misc/database/migrations/20180822140819_cria_nova_coluna_query_em_auditoria_geral.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaNovaColunaQueryEmAuditoriaGeral extends AbstractMigration | ||
{ | ||
public function up() | ||
{ | ||
$this->execute('ALTER TABLE modules.auditoria_geral ADD COLUMN query text;'); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->execute('ALTER TABLE modules.auditoria_geral drop COLUMN query;'); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822141028_cria_trigger_audita_nota_geral.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaNotaGeral extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_nota_geral() RETURNS TRIGGER AS $trigger_audita_nota_geral$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_NOTA_GERAL', TO_JSON(OLD.*),NULL,NOW(),OLD.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_NOTA_GERAL', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_NOTA_GERAL', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_nota_geral$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_nota_geral | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.nota_geral | ||
FOR EACH ROW EXECUTE PROCEDURE audita_nota_geral(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822143918_cria_trigger_audita_nota_exame.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaNotaExame extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_nota_exame() RETURNS TRIGGER AS $trigger_audita_nota_exame$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_NOTA_EXAME', TO_JSON(OLD.*),NULL,NOW(),json_build_object('ref_cod_matricula', OLD.ref_cod_matricula, 'ref_cod_componente_curricular',OLD.ref_cod_componente_curricular) ,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_NOTA_EXAME', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),json_build_object('ref_cod_matricula', NEW.ref_cod_matricula, 'ref_cod_componente_curricular',NEW.ref_cod_componente_curricular) ,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_NOTA_EXAME', NULL,TO_JSON(NEW.*),NOW(),json_build_object('ref_cod_matricula', NEW.ref_cod_matricula, 'ref_cod_componente_curricular',NEW.ref_cod_componente_curricular),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_nota_exame$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_nota_exame | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.nota_exame | ||
FOR EACH ROW EXECUTE PROCEDURE audita_nota_exame(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...isc/database/migrations/20180822144312_cria_trigger_audita_nota_componente_curricular.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaNotaComponenteCurricular extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_nota_componente_curricular() RETURNS TRIGGER AS $trigger_audita_nota_componente_curricular$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),NULL,NOW(),OLD.id ,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_nota_componente_curricular$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_nota_componente_curricular | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.nota_componente_curricular | ||
FOR EACH ROW EXECUTE PROCEDURE audita_nota_componente_curricular(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...tabase/migrations/20180822144436_cria_trigger_audita_nota_componente_curricular_media.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaNotaComponenteCurricularMedia extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_nota_componente_curricular_media() RETURNS TRIGGER AS $trigger_audita_nota_componente_curricular_media$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR_MEDIA', TO_JSON(OLD.*),NULL,NOW(),json_build_object('nota_aluno_id', OLD.nota_aluno_id, 'componente_curricular_id',OLD.componente_curricular_id, 'etapa',OLD.etapa),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR_MEDIA', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),json_build_object('nota_aluno_id', NEW.nota_aluno_id, 'componente_curricular_id',OLD.componente_curricular_id, 'etapa',OLD.etapa),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_NOTA_COMPONENTE_CURRICULAR_MEDIA', NULL,TO_JSON(NEW.*),NOW(),json_build_object('nota_aluno_id', NEW.nota_aluno_id, 'componente_curricular_id',NEW.componente_curricular_id, 'etapa',NEW.etapa),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_nota_componente_curricular_media$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_nota_componente_curricular_media | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.nota_componente_curricular_media | ||
FOR EACH ROW EXECUTE PROCEDURE audita_nota_componente_curricular_media(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822144605_cria_trigger_audita_parecer_geral.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaParecerGeral extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_parecer_geral() RETURNS TRIGGER AS $trigger_audita_parecer_geral$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_PARECER_GERAL', TO_JSON(OLD.*),NULL,NOW(),OLD.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_PARECER_GERAL', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_PARECER_GERAL', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_parecer_geral$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_parecer_geral | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.parecer_geral | ||
FOR EACH ROW EXECUTE PROCEDURE audita_parecer_geral(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../database/migrations/20180822144712_cria_trigger_audita_parecer_componente_curricular.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaParecerComponenteCurricular extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_parecer_componente_curricular() RETURNS TRIGGER AS $trigger_audita_parecer_componente_curricular$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_PARECER_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),NULL,NOW(),OLD.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_PARECER_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_PARECER_COMPONENTE_CURRICULAR', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_parecer_componente_curricular$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_parecer_componente_curricular | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.parecer_componente_curricular | ||
FOR EACH ROW EXECUTE PROCEDURE audita_parecer_componente_curricular(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822144839_cria_trigger_audita_falta_geral.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaFaltaGeral extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_falta_geral() RETURNS TRIGGER AS $trigger_audita_falta_geral$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_FALTA_GERAL', TO_JSON(OLD.*),NULL,NOW(),nextval('auditoria_geral_id_seq'),OLD.id,current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_FALTA_GERAL', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_FALTA_GERAL', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_falta_geral$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_falta_geral | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.falta_geral | ||
FOR EACH ROW EXECUTE PROCEDURE audita_falta_geral(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...sc/database/migrations/20180822145032_cria_trigger_audita_falta_componente_curricular.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaFaltaComponenteCurricular extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION modules.audita_falta_componente_curricular() RETURNS TRIGGER AS $trigger_audita_falta_componente_curricular$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_FALTA_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),NULL,NOW(),OLD.id ,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_FALTA_COMPONENTE_CURRICULAR', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_FALTA_COMPONENTE_CURRICULAR', NULL,TO_JSON(NEW.*),NOW(),NEW.id,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_falta_componente_curricular$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_falta_componente_curricular | ||
AFTER INSERT OR UPDATE OR DELETE ON modules.falta_componente_curricular | ||
FOR EACH ROW EXECUTE PROCEDURE audita_falta_componente_curricular(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822145147_cria_trigger_audita_matricula.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaMatricula extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION pmieducar.audita_matricula() RETURNS TRIGGER AS $trigger_audita_matricula$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_MATRICULA', TO_JSON(OLD.*),NULL,NOW(),OLD.cod_matricula ,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_MATRICULA', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),NEW.cod_matricula,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_MATRICULA', NULL,TO_JSON(NEW.*),NOW(),NEW.cod_matricula,nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_matricula$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_matricula | ||
AFTER INSERT OR UPDATE OR DELETE ON pmieducar.matricula | ||
FOR EACH ROW EXECUTE PROCEDURE audita_matricula(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
ieducar/misc/database/migrations/20180822145248_cria_trigger_audita_matricula_turma.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CriaTriggerAuditaMatriculaTurma extends AbstractMigration | ||
{ | ||
public function change() | ||
{ | ||
$sql = <<<'SQL' | ||
CREATE OR REPLACE FUNCTION pmieducar.audita_matricula_turma() RETURNS TRIGGER AS $trigger_audita_matricula_turma$ | ||
BEGIN | ||
IF (TG_OP = 'DELETE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 3, 'TRIGGER_MATRICULA_TURMA', TO_JSON(OLD.*),NULL,NOW(),json_build_object('ref_cod_matricula',OLD.ref_cod_matricula,'sequencial',OLD.sequencial),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN OLD; | ||
END IF; | ||
IF (TG_OP = 'UPDATE') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 2, 'TRIGGER_MATRICULA_TURMA', TO_JSON(OLD.*),TO_JSON(NEW.*),NOW(),json_build_object('ref_cod_matricula',NEW.ref_cod_matricula,'sequencial',NEW.sequencial),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
IF (TG_OP = 'INSERT') THEN | ||
INSERT INTO modules.auditoria_geral VALUES(1, 1, 'TRIGGER_MATRICULA_TURMA', NULL,TO_JSON(NEW.*),NOW(),json_build_object('ref_cod_matricula',NEW.ref_cod_matricula,'sequencial',NEW.sequencial),nextval('auditoria_geral_id_seq'),current_query()); | ||
RETURN NEW; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$trigger_audita_matricula_turma$ language plpgsql; | ||
CREATE TRIGGER trigger_audita_matricula_turma | ||
AFTER INSERT OR UPDATE OR DELETE ON pmieducar.matricula_turma | ||
FOR EACH ROW EXECUTE PROCEDURE audita_matricula_turma(); | ||
SQL; | ||
|
||
$this->execute($sql); | ||
} | ||
} |
Oops, something went wrong.