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

PostgresDbAdapter reseed issues #95

Open
tsanton opened this issue Apr 16, 2022 · 1 comment
Open

PostgresDbAdapter reseed issues #95

tsanton opened this issue Apr 16, 2022 · 1 comment

Comments

@tsanton
Copy link

tsanton commented Apr 16, 2022

Hi Jimmy, and again: great lib :)

There seems to be an issue with PostgresDbAdapter.BuildReseedSql

The issue boils down to a mismatch between the C# & PgSQL table name concatenation:

Here's the GetFullName:

public string GetFullName(char quoteIdentifier) =>
            Schema == null
                ? $"{quoteIdentifier}{Name}{quoteIdentifier}"
                : $"{quoteIdentifier}{Schema}{quoteIdentifier}.{quoteIdentifier}{Name}{quoteIdentifier}";
//for table {"schema":"public","table": "a"}
var tableNames = string.Join(", ", tablesToDelete.Select(t => $"'{t.GetFullName(QuoteCharacter)}'"));
//Given quote char " yielding:'"public"."a"'
--Given schema:table 'public:a'
//....
where AND '""' || table_schema || '"".""' || table_name || '""' IN ({tableNames})
--Here the where resolves to '"public"".""a"' IN ({tableNames})

To test it run the following:

create table public.a (id int generated always as identity(start with 1 increment by 1), val int);
create table public.b (id serial, val int);

select
    isc.table_schema,
    isc.table_name,
    '"' || isc.table_schema || '"".""' || isc.table_name || '"' wrong_but_currently_implemented_format,
    '"' || isc.table_schema || '"."' || isc.table_name || '"' suggested_fix
FROM information_schema.columns isc
where isc.table_schema in('public')

I'd be happy to PR the quote-fix if you'd like!

/Tobias

@jbogard
Copy link
Owner

jbogard commented Apr 16, 2022

Sure! A test would be great too.

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

No branches or pull requests

2 participants