-
Notifications
You must be signed in to change notification settings - Fork 184
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
PostgreSQL Support #367
PostgreSQL Support #367
Conversation
…aving zero administrator accounts)
Added: UsePostgresSQL setting Updated: README.md
@Bram1903 |
I have done some refactoring in the PR #367. I haven't had the time to test it yet due to my unpredictable schedule. Thank you very much for your contribution. Let's work together to complete this feature. |
I'm going to get some breakfast, and I'll take a look afterward. What still needs to be done, and how do you normally create migrations, as that might come in handy while working on this feature? |
Please test whether this project can run using a PostgreSQL database. Currently, I don't have the necessary database environment set up, but you can easily modify the parameters in the DatabaseSettings to support different databases. Good luck with the testing, and let me know if you have any questions about how to approach the migration process! |
Sure. I have the testing environment setup anyways. I'll start testing with the current PR branch, and return feedback when needed. How do you normally create a migration? |
Yesterday I added the following line of code to solve this issue. Ideally, we only want to enable AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); |
Removed: Unnecessary usings Changed: Reduced nesting by inverting two if statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Everything seems to work with PostgreSQL. I enabled I did notice that when trying to use the connection string provided by you with the external database the website doesn't seem to launch correctly, but I'm uncertain what this might have caused. When using my own running instance everything works perfectly fine, just as it did yesterday without this new clean approach! |
Yes, connecting to the locally running PostgreSQL database works fine. |
I think this PR is a great addition to the already existing codebase because many people will benefit from being able to use another Database! Besides that adding additional support for a new Database has also become significantly easier. Great collaboration! |
PostgreSQL Support
Features included in this PR:
I added PostgreSQL support and tried to do it as generic as possible. To achieve support for PostgreSQL I added an additional setting within the
appsettings.json
.Due to the nature of the PostgreSQL connection string being built up slightly differently than MS SQL Server, especially when not using any authentication I decided to create an additional connection string.
Updated
appsettings.json
:Testing
I have tested this code both on a traditional x64 processor and on an Arm (M2 Max) processor.
Tested OS Versions:
Tested Database Versions:
Important Side Note
Since the migrations look different depending on the active database provider, migrations need to be made separately for both MS SQL Server and PostgreSQL.
I currently achieve this by setting
Blazor.Server.UI
as migration assembly, when using the PostgreSQL provider. This ends up creating migrations in a Migrations folder on theBlazor.Server.UI
project. Obviously, this isn't considered "Clean Architecture".Currently, I create migrations by executing
dotnet ef migrations add migrationsName
in theBlazor.Server.UI
directory. I tried to create a new migration for MS SQL Server, in your traditional way, but I couldn't figure out how to create one. 😅Most probably I looked over something, but if you could let me know how you normally create your migrations that would be great! :-)
I hope you could look into the best and cleanest way of storing two separate migrations for two different providers!
Even though the changes may look small, I had to spend quite some time researching how I could implement another database provider, without changing too much of the codebase. Luckily the PostgreSQL provider supports
which handles all the datetime conversions between the MS SQL Server standard to the PostgreSQL standard.
If you have any questions feel free to ask them!