55using DbUp . Engine . Transactions ;
66using DbUp . Support ;
77
8- namespace DbUp . Postgresql
8+ namespace DbUp . Postgresql ;
9+
10+ /// <summary>
11+ /// An implementation of the <see cref="IJournal"/> interface which tracks version numbers for a
12+ /// PostgreSQL database using a table called SchemaVersions.
13+ /// </summary>
14+ public class PostgresqlTableJournal : TableJournal
915{
1016 /// <summary>
11- /// An implementation of the <see cref="IJournal"/> interface which tracks version numbers for a
12- /// PostgreSQL database using a table called SchemaVersions.
17+ /// Creates a new PostgreSQL table journal.
1318 /// </summary>
14- public class PostgresqlTableJournal : TableJournal
19+ /// <param name="connectionManager">The PostgreSQL connection manager.</param>
20+ /// <param name="logger">The upgrade logger.</param>
21+ /// <param name="schema">The name of the schema the journal is stored in.</param>
22+ /// <param name="tableName">The name of the journal table.</param>
23+ public PostgresqlTableJournal ( Func < IConnectionManager > connectionManager , Func < IUpgradeLog > logger , string schema , string tableName )
24+ : base ( connectionManager , logger , new PostgresqlObjectParser ( ) , schema , tableName )
1525 {
16- /// <summary>
17- /// Creates a new PostgreSQL table journal.
18- /// </summary>
19- /// <param name="connectionManager">The PostgreSQL connection manager.</param>
20- /// <param name="logger">The upgrade logger.</param>
21- /// <param name="schema">The name of the schema the journal is stored in.</param>
22- /// <param name="tableName">The name of the journal table.</param>
23- public PostgresqlTableJournal ( Func < IConnectionManager > connectionManager , Func < IUpgradeLog > logger , string schema , string tableName )
24- : base ( connectionManager , logger , new PostgresqlObjectParser ( ) , schema , tableName )
25- {
26- }
26+ }
2727
28- protected override IDbCommand GetInsertScriptCommand ( Func < IDbCommand > dbCommandFactory , SqlScript script )
29- {
30- // EnableSqlRewriting is enabled by default, and needs to be explicitly disabled
31- bool enableSqlRewriting = ! AppContext . TryGetSwitch ( "Npgsql.EnableSqlRewriting" , out bool enabled ) || enabled ;
28+ protected override IDbCommand GetInsertScriptCommand ( Func < IDbCommand > dbCommandFactory , SqlScript script )
29+ {
30+ // EnableSqlRewriting is enabled by default, and needs to be explicitly disabled
31+ bool enableSqlRewriting = ! AppContext . TryGetSwitch ( "Npgsql.EnableSqlRewriting" , out bool enabled ) || enabled ;
3232
33- if ( enableSqlRewriting )
34- return base . GetInsertScriptCommand ( dbCommandFactory , script ) ;
33+ if ( enableSqlRewriting )
34+ return base . GetInsertScriptCommand ( dbCommandFactory , script ) ;
3535
36- // Use positional parameters instead of named parameters
37- var command = dbCommandFactory ( ) ;
36+ // Use positional parameters instead of named parameters
37+ var command = dbCommandFactory ( ) ;
3838
39- var scriptNameParam = command . CreateParameter ( ) ;
40- scriptNameParam . Value = script . Name ;
41- command . Parameters . Add ( scriptNameParam ) ;
39+ var scriptNameParam = command . CreateParameter ( ) ;
40+ scriptNameParam . Value = script . Name ;
41+ command . Parameters . Add ( scriptNameParam ) ;
4242
43- var appliedParam = command . CreateParameter ( ) ;
44- appliedParam . Value = DateTime . Now ;
45- command . Parameters . Add ( appliedParam ) ;
43+ var appliedParam = command . CreateParameter ( ) ;
44+ appliedParam . Value = DateTime . Now ;
45+ command . Parameters . Add ( appliedParam ) ;
4646
47- command . CommandText = GetInsertJournalEntrySql ( "$1" , "$2" ) ;
48- command . CommandType = CommandType . Text ;
49- return command ;
50- }
47+ command . CommandText = GetInsertJournalEntrySql ( "$1" , "$2" ) ;
48+ command . CommandType = CommandType . Text ;
49+ return command ;
50+ }
5151
52- protected override string GetInsertJournalEntrySql ( string scriptName , string applied )
53- {
54- return $ "insert into { FqSchemaTableName } (ScriptName, Applied) values ({ scriptName } , { applied } )";
55- }
52+ protected override string GetInsertJournalEntrySql ( string scriptName , string applied )
53+ {
54+ return $ "insert into { FqSchemaTableName } (ScriptName, Applied) values ({ scriptName } , { applied } )";
55+ }
5656
57- protected override string GetJournalEntriesSql ( )
58- {
59- return $ "select ScriptName from { FqSchemaTableName } order by ScriptName";
60- }
57+ protected override string GetJournalEntriesSql ( )
58+ {
59+ return $ "select ScriptName from { FqSchemaTableName } order by ScriptName";
60+ }
6161
62- protected override string CreateSchemaTableSql ( string quotedPrimaryKeyName )
63- {
64- return
65- $@ "CREATE TABLE { FqSchemaTableName }
62+ protected override string CreateSchemaTableSql ( string quotedPrimaryKeyName )
63+ {
64+ return
65+ $@ "CREATE TABLE { FqSchemaTableName }
6666(
6767 schemaversionsid serial NOT NULL,
6868 scriptname character varying(255) NOT NULL,
6969 applied timestamp without time zone NOT NULL,
7070 CONSTRAINT { quotedPrimaryKeyName } PRIMARY KEY (schemaversionsid)
7171)" ;
72- }
7372 }
74- }
73+ }
0 commit comments