Last active
July 11, 2023 10:28
-
-
Save NerdGr8/000fe982fe6731585a561f451a257761 to your computer and use it in GitHub Desktop.
Generates Alter Columns statements to change any uncompliant columns to postgress naming conventions.
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
#Run teh following in the terminal: | |
Install-Package Npgsql.EntityFrameworkCore.PostgreSQL |
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
-- Generate the SQL Statement required to conform All Columns in the Schema. | |
-- Will pick up and columns ie: | |
-- CreatedDate => created | |
-- Created => created | |
-- Created Date => created_date | |
SELECT FORMAT( | |
'ALTER TABLE %I.%I.%I RENAME COLUMN %I TO %I;', | |
table_catalog, | |
table_schema, | |
table_name, | |
column_name, | |
lower( | |
-- replace all spaces with _, xX and Xx becomes x_x | |
regexp_replace( | |
-- First, replace spaces with an _ | |
replace(column_name, ' ', '_'), | |
'([[:lower:]])([[:upper:]])', | |
'\1_\2', | |
'g' | |
) | |
) | |
) | |
FROM information_schema.columns | |
WHERE column_name ~ ' |[[:lower:]][[:upper:]]' OR column_name ~ '^[A-Z]'; |
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
Add-Migration InitialCreate | |
Update-Database |
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
//Change the following | |
services.AddDbContext<YourContext>(options => | |
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment