Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for table and column renaming using Regex #496

Merged
merged 6 commits into from
Sep 10, 2020
Merged

Adding support for table and column renaming using Regex #496

merged 6 commits into from
Sep 10, 2020

Conversation

evandromendonca
Copy link
Contributor

Hello, first I'd like to thank you for this tool, it has been very useful and I am more than happy to contribute.

I had the need to remove some prefixes from my tables. I found out this thread but didn't want to map my entire database.

So I took inspiration from there and included 4 new properties in the Schema object. These will receive the pattern to be matched and a string to replace tables and columns names.

TableRegexPattern: pattern to be matched by table names
TablePatternReplaceWith: string that will replace the occurrences of the pattern in tables names
ColumnRegexPattern: pattern to be matched by column names
ColumnPatternReplaceWith: string that will replace the occurrences of the pattern in columns names

The regex renaming also have lower priority over the current renaming method, and therefore, if a table is renamed using "NewName", the NewName method will prevail over the regex

Example of use:

efpt.renaming.json

[
  {
    "UseSchemaName": false,
    "SchemaName": "dbo",
    "TableRegexPattern": "^Old",
    "TablePatternReplaceWith": "New",
    "ColumnRegexPattern": "^Old",
    "ColumnPatternReplaceWith": "New",
    "Tables": [
      {
        "Name": "course_sched",
        "NewName":  "CourseOffering",
        "Columns": [
          {
            "Name": "subj_area_cd",
            "NewName": "SubjectArea"
          }
        ]
      }
    ]
  }
]

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 9, 2020

You must rebase on latest master

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 9, 2020

Would it be possible to design for expetions from the general rules for individual tables and/or columns?

@evandromendonca
Copy link
Contributor Author

Would it be possible to design for expetions from the general rules for individual tables and/or columns?

Sorry, I didn't understand what you meant there.

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 9, 2020

I just didn't read this properly:

The regex renaming also have lower priority over the current renaming method, and therefore, if a table is renamed using "NewName", the NewName method will prevail over the regex.

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 10, 2020

Please address review comments

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 10, 2020

Great, thanks a lot for the contribution

@ErikEJ ErikEJ merged commit b3c37ea into ErikEJ:master Sep 10, 2020
@jamshally
Copy link

This is a great feature. Thanks!

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 18, 2020

You are welcome, agree that it rounds out the renaming feature nicely.

@ErikEJ ErikEJ mentioned this pull request Sep 18, 2020
@e-ngin
Copy link

e-ngin commented Oct 30, 2020

I'm sorry but I don't understand how to use this feature.

i add

"TableRegexPattern": "^.+",
"TablePatternReplaceWith": "$0Entity"

to the efpt.config.json file but it gets overwritten when i rerun the reverse engineer.

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 30, 2020

@engineruguz No worries - You got the file name wrong - see https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#custom-renaming-with-efptrenamingjson

@e-ngin
Copy link

e-ngin commented Oct 30, 2020

oooh! i see. feel dumb lol

@e-ngin
Copy link

e-ngin commented Oct 30, 2020

hi! sorry. i still can't find out why it's not working? i created efpt.renaming.json file at project root like below.

{
  "UseSchemaName": false,
  "SchemaName": "dbo",
  "TableRegexPattern": "^.+$",
  "TablePatternReplaceWith": "$0Entity"
}

i'm trying to add Entity at the end of every table. not sure about $0 is the correct syntax though but not getting anything different.

@ErikEJ
Copy link
Owner

ErikEJ commented Oct 30, 2020

Wrong file format...

@e-ngin
Copy link

e-ngin commented Oct 30, 2020

uh ofc! sorry. thanks

@marcziss
Copy link

Either I'm doing something very dumb or there's an issue with ColumnPatternReplaceWith

{
"ColumnPatternReplaceWith": "TEST_COLUMN_",
"ColumnRegexPattern": "^",
"SchemaName": "PDM",
"TablePatternReplaceWith": "TEST_TABLE_",
"TableRegexPattern": "^",
"UseSchemaName": false
}

In this example using .net 5 (and latest version of vsix installed today) Every table is renamed properly with the TEST_TABLE_ prefix, however no column is renamed at all. Is there something I'm missing?

@ErikEJ
Copy link
Owner

ErikEJ commented Mar 14, 2021

@marcziss if you have an issue, please create one with detailed repro steps.

@HansB159
Copy link

HansB159 commented Jun 7, 2021

@marcziss I struggled with the same problem. Solution: add "Table: []". That magically worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants