@@ -21,7 +21,7 @@ public enum SyncDirection
2121/// </summary>
2222public sealed partial class SyncScriptGenerator
2323{
24- [ GeneratedRegex ( @"^\s*CREATE\s+(VIEW|PROCEDURE|PROC)\b" , RegexOptions . IgnoreCase ) ]
24+ [ GeneratedRegex ( @"^\s*CREATE\s+(VIEW|PROCEDURE|PROC|TRIGGER )\b" , RegexOptions . IgnoreCase ) ]
2525 private static partial Regex CreateModule ( ) ;
2626
2727 public string Generate ( IEnumerable < ObjectComparison > selected , SyncDirection direction ,
@@ -44,17 +44,19 @@ public string Generate(IEnumerable<ObjectComparison> selected, SyncDirection dir
4444 sb . AppendLine ( "GO" ) ;
4545 sb . AppendLine ( ) ;
4646
47- // Ordem para DROP: procedures -> views -> índices -> tabelas
47+ // Ordem para DROP: triggers -> procedures -> views -> índices -> tabelas
48+ EmitDrops ( sb , items , direction , DbObjectType . Trigger ) ;
4849 EmitDrops ( sb , items , direction , DbObjectType . Procedure ) ;
4950 EmitDrops ( sb , items , direction , DbObjectType . View ) ;
5051 EmitDrops ( sb , items , direction , DbObjectType . Index ) ;
5152 EmitDrops ( sb , items , direction , DbObjectType . Table ) ;
5253
53- // Ordem para CREATE/ALTER: tabelas -> índices -> views -> procedures
54+ // Ordem para CREATE/ALTER: tabelas -> índices -> views -> procedures -> triggers
5455 EmitCreates ( sb , items , direction , DbObjectType . Table ) ;
5556 EmitCreates ( sb , items , direction , DbObjectType . Index ) ;
5657 EmitCreates ( sb , items , direction , DbObjectType . View ) ;
5758 EmitCreates ( sb , items , direction , DbObjectType . Procedure ) ;
59+ EmitCreates ( sb , items , direction , DbObjectType . Trigger ) ;
5860
5961 sb . AppendLine ( "COMMIT TRANSACTION;" ) ;
6062 sb . AppendLine ( "GO" ) ;
@@ -123,8 +125,8 @@ private void EmitCreates(StringBuilder sb, List<ObjectComparison> items,
123125
124126 private string CreateStatement ( DbObject source , CompareStatus status )
125127 {
126- // Views/Procedures alteradas usam CREATE OR ALTER.
127- if ( source . Type is DbObjectType . View or DbObjectType . Procedure )
128+ // Views/Procedures/Triggers alterados usam CREATE OR ALTER.
129+ if ( source . Type is DbObjectType . View or DbObjectType . Procedure or DbObjectType . Trigger )
128130 {
129131 var ddl = source . RawDefinition ;
130132 if ( status == CompareStatus . Different && CreateModule ( ) . IsMatch ( ddl ) )
@@ -136,16 +138,17 @@ private string CreateStatement(DbObject source, CompareStatus status)
136138 return source . RawDefinition ;
137139 }
138140
139- // Views e Procedures são "módulos": seus scripts saem sem os comentários de marcação.
141+ // Views, Procedures e Triggers são "módulos": seus scripts saem sem os comentários de marcação.
140142 private static bool IsModule ( DbObjectType type ) =>
141- type is DbObjectType . View or DbObjectType . Procedure ;
143+ type is DbObjectType . View or DbObjectType . Procedure or DbObjectType . Trigger ;
142144
143145 private static string DropStatement ( ObjectComparison c )
144146 {
145147 return c . Type switch
146148 {
147149 DbObjectType . Procedure => $ "DROP PROCEDURE IF EXISTS { c . FullName } ;",
148150 DbObjectType . View => $ "DROP VIEW IF EXISTS { c . FullName } ;",
151+ DbObjectType . Trigger => $ "DROP TRIGGER IF EXISTS { c . FullName } ;",
149152 DbObjectType . Table => $ "DROP TABLE IF EXISTS { c . FullName } ;",
150153 DbObjectType . Index => DropIndex ( c ) ,
151154 _ => $ "-- DROP não suportado para { c . Type } "
0 commit comments