12
12
* express or implied. See the License for the specific
13
13
* language governing rights and limitations under the License.
14
14
*
15
- * Copyright (c) 2014 Jiri Cincura ([email protected] )
15
+ * Copyright (c) 2014,2017 Jiri Cincura ([email protected] )
16
16
* All Rights Reserved.
17
17
*
18
18
*/
@@ -28,24 +28,23 @@ namespace FirebirdSql.Data.EntityFramework6
28
28
{
29
29
public class DefaultFbMigrationSqlGeneratorBehavior : IFbMigrationSqlGeneratorBehavior
30
30
{
31
- const string IdentitySequenceName = "GEN_IDENTITY" ;
32
-
33
- public IEnumerable < string > CreateIdentityForColumn ( string columnName , string tableName )
31
+ public virtual IEnumerable < string > CreateIdentityForColumn ( string columnName , string tableName )
34
32
{
33
+ var identitySequenceName = CreateIdentitySequenceName ( columnName , tableName ) ;
35
34
using ( var writer = FbMigrationSqlGenerator . SqlWriter ( ) )
36
35
{
37
36
writer . WriteLine ( "EXECUTE BLOCK" ) ;
38
37
writer . WriteLine ( "AS" ) ;
39
38
writer . WriteLine ( "BEGIN" ) ;
40
39
writer . Indent ++ ;
41
40
writer . Write ( "if (not exists(select 1 from rdb$generators where rdb$generator_name = '" ) ;
42
- writer . Write ( IdentitySequenceName ) ;
41
+ writer . Write ( identitySequenceName ) ;
43
42
writer . Write ( "')) then" ) ;
44
43
writer . WriteLine ( ) ;
45
44
writer . WriteLine ( "begin" ) ;
46
45
writer . Indent ++ ;
47
46
writer . Write ( "execute statement 'create sequence " ) ;
48
- writer . Write ( IdentitySequenceName ) ;
47
+ writer . Write ( identitySequenceName ) ;
49
48
writer . Write ( "';" ) ;
50
49
writer . WriteLine ( ) ;
51
50
writer . Indent -- ;
@@ -74,7 +73,7 @@ public IEnumerable<string> CreateIdentityForColumn(string columnName, string tab
74
73
writer . Write ( "new." ) ;
75
74
writer . Write ( FbMigrationSqlGenerator . Quote ( columnName ) ) ;
76
75
writer . Write ( " = next value for " ) ;
77
- writer . Write ( IdentitySequenceName ) ;
76
+ writer . Write ( identitySequenceName ) ;
78
77
writer . Write ( ";" ) ;
79
78
writer . WriteLine ( ) ;
80
79
writer . Indent -- ;
@@ -85,7 +84,7 @@ public IEnumerable<string> CreateIdentityForColumn(string columnName, string tab
85
84
}
86
85
}
87
86
88
- public IEnumerable < string > DropIdentityForColumn ( string columnName , string tableName )
87
+ public virtual IEnumerable < string > DropIdentityForColumn ( string columnName , string tableName )
89
88
{
90
89
var triggerName = CreateTriggerName ( columnName , tableName ) ;
91
90
using ( var writer = FbMigrationSqlGenerator . SqlWriter ( ) )
@@ -112,9 +111,14 @@ public IEnumerable<string> DropIdentityForColumn(string columnName, string table
112
111
}
113
112
}
114
113
115
- static string CreateTriggerName ( string columnName , string tableName )
114
+ protected virtual string CreateTriggerName ( string columnName , string tableName )
116
115
{
117
116
return string . Format ( "ID_{0}_{1}" , tableName , columnName ) ;
118
117
}
118
+
119
+ protected virtual string CreateIdentitySequenceName ( string columnName , string tableName )
120
+ {
121
+ return "GEN_IDENTITY" ;
122
+ }
119
123
}
120
124
}
0 commit comments