Skip to content

Commit 138c208

Browse files
committed
Improve the PostgreSQL scripts
* Use PostgreSQL naming conventions * snake_case for table and coumn names, see [PostgreSQL naming conventions][1] * pkey/fkey/idx suffix for constraint names, see [PostgreSQL: default constraint names][2] * Add a script with auto incremented PKs [1]: https://stackoverflow.com/questions/2878248/postgresql-naming-conventions/2878408#2878408 [2]: https://stackoverflow.com/questions/4107915/postgresql-default-constraint-names/4108266#4108266
1 parent 9208a2d commit 138c208

File tree

10 files changed

+31733
-15837
lines changed

10 files changed

+31733
-15837
lines changed

‎ChinookDatabase/DataSources/ChinookDatabase.tt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var options = new
2222
new MySqlStrategy { IsIdentityEnabled = true },
2323
new OracleStrategy { IsIdentityEnabled = false, Encoding = Encoding.UTF8 },
2424
new PostgreSqlStrategy { IsIdentityEnabled = false, Encoding = Encoding.Default },
25+
new PostgreSqlStrategy { IsIdentityEnabled = true, Encoding = Encoding.Default },
2526
new Db2Strategy { IsIdentityEnabled = false, Encoding = Encoding.Default }
2627
},
2728
OutputFiles = new List<OutputFile>()
@@ -160,7 +161,7 @@ CREATE TABLE <#= strategy.GetFullyQualifiedName(tableName) #>
160161
if (strategy.PrimaryKeyDef==KeyDefinition.OnCreateTableBottom ||
161162
(strategy.PrimaryKeyDef==KeyDefinition.OnCreateTableColumn && keys.Count() > 1))
162163
{
163-
string pkName = strategy.FormatName("PK_" + tableName);#>,
164+
string pkName = strategy.FormatPrimaryKey(tableName);#>,
164165
CONSTRAINT <#= pkName #> PRIMARY KEY <#= strategy.GetClustered(table)#> (<#= strategy.GetColumns(keys, ',')#>)<#
165166
}
166167

@@ -202,7 +203,7 @@ CREATE TABLE <#= strategy.GetFullyQualifiedName(tableName) #>
202203
// Create Primary Key Constraint.
203204
if (strategy.PrimaryKeyDef==KeyDefinition.OnAlterTable)
204205
{
205-
string pkName = strategy.FormatName("PK_" + tableName);
206+
string pkName = strategy.FormatPrimaryKey(tableName);
206207
#>
207208
ALTER TABLE <#= tableName #> ADD CONSTRAINT <#= pkName #> PRIMARY KEY (<#= strategy.GetColumns(keys, ',')#>);
208209
<#= strategy.WriteExecuteCommand() #>
@@ -234,9 +235,8 @@ CREATE UNIQUE INDEX <#= pkIndexName #> ON <#= tableName #>(<#= strategy.GetColum
234235
{
235236
var toTableName = fk.RelatedTable.TableName;
236237
var fromTableName = table.TableName;
237-
var constraintName = "FK_" + fromTableName + fk.Columns[0].ColumnName;
238-
var fkName = strategy.FormatName(constraintName);
239-
var ifkName = strategy.FormatName("I" + constraintName);
238+
var fkName = strategy.FormatForeignKey(fromTableName, fk.Columns[0].ColumnName);
239+
var ifkName = strategy.FormatForeignKeyIndex(fromTableName, fk.Columns[0].ColumnName);
240240

241241
if (strategy.ForeignKeyDef==KeyDefinition.OnAlterTable)
242242
{

‎ChinookDatabase/DataSources/ChinookDatabase.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-

21
Chinook Database 1.4.2
32
* This is a sample database available in multiple formats: SQL scripts for multiple database vendors, embeded database files, and XML format.
43
* The Chinook data model is available [here|Chinook_Schema].
@@ -29,6 +28,7 @@ This is the list of files included in the complete version.
2928
| Oracle | {"Chinook_Oracle.sql"} | SQL script to create the Chinook database. |
3029
| Oracle | {"CreateOracle.bat"} | Batch file to create the Chinook database. |
3130
| PostgreSql | {"Chinook_PostgreSql.sql"} | SQL script to create the Chinook database. |
31+
| PostgreSql | {"Chinook_PostgreSql_AutoIncrementPKs.sql"} | SQL script to create the Chinook database. Auto incremented primary keys. |
3232
| PostgreSql | {"CreatePostgreSql.bat"} | Batch file to create the Chinook database. |
3333
| Sqlite | {"Chinook_Sqlite.sql"} | SQL script to create the Chinook database. |
3434
| Sqlite | {"Chinook_Sqlite.sqlite"} | Chinook database file. |

‎ChinookDatabase/DataSources/Chinook_PostgreSql.sql‎

Lines changed: 15820 additions & 15820 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)