-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Initial setup fails when Database Shells is active #15447
Comments
I forgot to mention, but this happens with SQL Server and Azure SQL. I'm not sure if this happens with MySQL or PostgresSQL. |
Can you explain what values you use for this? |
I apologize for the delayed response. We've been using values similar to these: appsettings.json{
"UseSerilog": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "example.com",
"OrchardCore": {
"OrchardCore_Shells_Database": {
"DatabaseProvider": "SqlConnection",
"ConnectionString": "Server=tcp:XXXXXXXXX.database.windows.net,1433;Initial Catalog=XXXXXXXXX-dev;Persist Security Info=False;User ID=XXXXXXXXX;Password=XXXXXXXXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"TablePrefix": "",
"MigrateFromFiles": true
},
...
}
} Or when database shells are configured with App Service environment variables:OrchardCore__OrchardCore_Shells_Database__DatabaseProvider="SqlConnection"
OrchardCore__OrchardCore_Shells_Database__ConnectionString="Server=tcp:XXXXXXXXX.database.windows.net,1433;Initial Catalog=XXXXXXXXX-dev;Persist Security Info=False;User ID=XXXXXXXXX;Password=XXXXXXXXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" I don't know if the During the setup, the |
Have you tried to change the settings to match the column type you are already using which is not the new default? Like this: https://github.com/OrchardCMS/OrchardCore/blob/main/src/OrchardCore.Cms.Web/appsettings.json#L26 Please see this changelog: https://docs.orchardcore.net/en/latest/docs/releases/1.7.0/ |
I recently reproduced this issue with the following using Orchard 1.8.3:
I started the site, submitted the setup page, and then got the following error (with many follow-on errors):
But I get the same error if I change the IdentityColumnSize to Int32 (in both places). It seems that it just doesn't work to run the initial site setup with AddDatabaseShellsConfiguration in place? |
A bit more information. Maybe this was already obvious from the original issue description, but this fails:
and this works:
I was trying this with OrchardCore 1.8.3 with the initial (single) tenant setup. |
I did some debugging. The problem seems to be in ShellSettingsExtensions.GetIdentityColumnSize. If I set a breakpoint here and then start up a fresh OrchardCore tenant with the OrchardCore_Shells_Database settings and a call to AddDatabaseShellsConfiguration in my Program.cs... I hit the breakpoints in GetIdentityColumnSize several times as Orchard Core starts and builds the initial setup page. Each time the breakpoint hits... The above code block results in identityColumnSize of null. The shellSettings configuration is pretty empty at this point. It contains only ConnectionString, DatabaseProvider, Schema, and TablePrefix. If I add IdentityColumnSize to and/or DefaultIdentityColumnSize (in the appropriate section, as in my comment from yesterday) it doesn't matter. Those values do not appear in shellSettings. So GetIdentityColumnSize always falls into this if block: And the first time through, as it's preparing the setup page, IsInitialized returns true (shellSettings.State is Running) every time. So identityColumnSize gets set to Int32. Once the setup page is displayed (before I complete and submit it), I can see that the Document and Identifiers tables both exist. Those are the only tables in the DB. The Document table has two rows. One for ShellSettings and one for ShellConfigurations. Both are pretty empty (just a VersionId and TenantId in the shell settings JSON). But they were both created with Int32 identifiers. Now if I submit the setup form then the breakpoint in GetIdentityColumnSize hits again. But this time, two things have changed. The shellSettings.State is now Initializing. This would result in Int64 from the fallback logic: But also, shellSettings now contains the values for OrchardCore_Data_TableOptions, including DefaultIdentityColumnSize, which is Int64. So now, GetIdentityColumnSize returns Int64. And Orchard Core gives the errors which were described in the comments above. So, you can only use the database shells feature with Int32 columns. If you try to use it with Int64 (via the overrides or just by not specifying an override) you'll end up with a mix of Int32 (on the Document table) and Int64 identifier columns (on the rest) which does not work. @sebastienros I'm wondering why GetIdentityColumnSize doesn't always fall back to Int64? Why does it use Int32 as the default if the shellSettings are initialized? |
One more note from my debugging session... The shellSettings which are used early, when first displaying the setup page, are initialized by DatabaseShellContextFactoryExtensions. This is why it only has the four specific shell settings and nothing else and this is why the status is "Running": I see no way to get either the default identity column size or the identity column size settings injected in here (to allow me to override the strange default that flips between Int32 before the setup service initializes the tenant and Int64 after). |
I found a workaround of sorts. In my application, we're using a very limited set of OrchardCore modules. Instead of using AddOrchardCms in our Program.cs, we use AddOrchardCore. This allows me the flexibility to stick a Configure call onto the OrchardCoreBuilder right before I call AddDataAccess. I can use this to register an initializer that runs right before the initializer registered by AddDataAccess. Here I can hard code the identity column size to Int64.
This seems like a pretty hacky workaround, but it's working for me. With this solution I don't need to override any of the configuration settings for index size. (To be clear, I would have expected that I wouldn't need to override any of the settings since I want to use Int64 identity columns. I want to use Int64 identity columns specifically because they're supposed to be the default and I don't want to change the default. But, in fact, if I enable the database shells feature, I have to use this hack to use Int64 identity columns. If I wanted to use Int32 identity columns, then I could have used the normal settings-based mechanism to override the default.) |
Describe the bug
Initial setup fails when Database Shells is active. This does not happen when DefaultIdentityColumnSize is set to Int32.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Database is expected to initialize correctly with new default setting for the identity column size.
Screenshots
The text was updated successfully, but these errors were encountered: