question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get access to actual connection for migration

See original GitHub issue

In my case I need add some specific settings in Migration file. migrationBuilder.Sql(sqlcode)

If I correctly understand all operation in migration uses MasterConnection (postgres database). https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/8e97e4195b197ae3d16763704352acfffa95c73f/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs#L41

But for my settings I need actual connection to actual database. Can I somehow get access to connection. Maybe I can inherit from NpgsqlDatabaseCreator and use connection directly https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/8e97e4195b197ae3d16763704352acfffa95c73f/src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs#L22

Maybe there are other ways?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
westfincommented, Oct 31, 2018

I’m sorry I really was wrong. Raw SQL work fine.

My problem was in custom NpgsqlMigrationsSqlGenerator. I tryed reimplement Generate method to append some sql commands: https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/89b9742df7bebab9bdc92f259bb6ecf66da30365/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs#L601

I was inattentive. @roji @austindrenski Thank you for help.

0reactions
rojicommented, Oct 27, 2018

I’m probably misunderstanding something here, but the master connection is only used to create the database. The rest of the migration code - table creation and any additional raw SQL - happens on the regular connection to the database. So any ALTER DATABASE statement you specify in raw SQL should actually work fine. Can you please double-check and provide more detail?

Aside from that, we do support specifying the tablespace on the database, mainly because this is an option that must be specified in CREATE DATABASE and cannot be altered later. We can support other database creation (and alteration) options as needed, but anything that can be altered later should be easily doable with raw SQL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the current connection string inside an Entity ...
This works when you have a 'running' DbContext. using (var db = new YourDbContext()) { var connection = db.Database.Connection.
Read more >
Migration guide: Access to SQL Server
This guide teaches you how to migrate your Microsoft Access databases to Microsoft SQL Server by using SQL Server Migration Assistant for ...
Read more >
How to transfer data from your old Mac to a new ... - YouTube
Learn how to use Migration Assistant to transfer information from your ... A terrible way to transfer to a new Mac as using...
Read more >
Use the Migration Dashboard to Migrate to Workspace ...
In the Migration dashboard, in the Install the latest Workspace ONE Access Connector(s) section, click Get Started.
Read more >
Migration Plans: Sites
The first step when creating a migration plan in the Tableau Content Migration Tool is to sign in to the source and destination...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found