Failure on empty PostgreSQL DB initialization
Grosam opened this issue · 1 comments
Grosam commented
Describe the bug
When the platform is run with a connection string to an empty PostgreSQL DB, it fails to finish initialization of the database with the following error:
Failed executing DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO AspNetUsers (
Id,
IsAdministrator,
UserName,
NormalizedUserName,
PasswordHash,
SecurityStamp,
ConcurrencyStamp,
PasswordExpired,
Email,
NormalizedEmail,
EmailConfirmed,
PhoneNumberConfirmed,
TwoFactorEnabled,
LockoutEnabled,
AccessFailedCount,
CreatedDate
)
SELECT
'1eb2fa8ac6574541afdb525833dadb46',
1,
'admin',
'ADMIN',
'AHQSmKnSLYrzj9vtdDWWnUXojjpmuDW2cHvWloGL9UL3TC9UCfBmbIuR2YCyg4BpNg==',
'IK5VZXH6VRIZ3E6OKHEIS7TC24VT4RD3',
'47548002-dd64-48e0-bb51-e9516fd880c2',
1,
'admin@vc-demostore.com',
'ADMIN@VC-DEMOSTORE.COM',
1,
1,
0,
1,
0,
Now()
WHERE
NOT EXISTS (
SELECT
*
FROM
AspNetUsers
WHERE
UserName = 'admin'
);
Npgsql.PostgresException (0x80004005): 42P01: relation "aspnetusers" does not exist
Steps to reproduce
Steps to reproduce the behavior:
- Specify a PostgreSQL connection string in the appsettings
- Run the platform
Expected behavior
The DB is initialized with no error
Version info (please complete the following information):
- Platform version: 3.403.0
Additional context (optional)
It seems that the issue can be fixed by wrapping table and column names in double quotes and changing numbers to booleans in the SQL query mentioned in the error.
File:
VirtoCommerce.Platform.Data.PostgreSql\Migrations\Security\20221128141520_Initial.cs
migrationBuilder.Sql(@"INSERT INTO ""AspNetUsers"" (
""Id"",
""IsAdministrator"",
""UserName"",
""NormalizedUserName"",
""PasswordHash"",
""SecurityStamp"",
""ConcurrencyStamp"",
""PasswordExpired"",
""Email"",
""NormalizedEmail"",
""EmailConfirmed"",
""PhoneNumberConfirmed"",
""TwoFactorEnabled"",
""LockoutEnabled"",
""AccessFailedCount"",
""CreatedDate""
)
SELECT
'1eb2fa8ac6574541afdb525833dadb46',
true,
'admin',
'ADMIN',
'AHQSmKnSLYrzj9vtdDWWnUXojjpmuDW2cHvWloGL9UL3TC9UCfBmbIuR2YCyg4BpNg==',
'IK5VZXH6VRIZ3E6OKHEIS7TC24VT4RD3',
'47548002-dd64-48e0-bb51-e9516fd880c2',
true,
'admin@vc-demostore.com',
'ADMIN@VC-DEMOSTORE.COM',
true,
true,
false,
true,
0,
Now()
WHERE
NOT EXISTS (
SELECT
*
FROM
""AspNetUsers""
WHERE
""UserName"" = 'admin'
);");