# Migrate a Blazor App from SQL Server to PostgreSQL

Yes. An agent swaps a Blazor app's EF Core provider to Npgsql, regenerates the migrations, fixes what behaves differently on PostgreSQL and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/migrate-sql-server-to-postgres/blazor/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Changing the database under an EF Core app is a provider swap plus everything the old provider was doing without being asked. In a Blazor Web App like `10.0/BlazorWebAppMovies` in dotnet/blazor-samples, the agent reads `BlazorWebAppMovies.csproj`, which references `Microsoft.EntityFrameworkCore.SqlServer` 10.0.0, `Program.cs`, where the context factory is configured with `UseSqlServer`, and `appsettings.json`, whose only connection string targets `(localdb)\mssqllocaldb` with `Trusted_Connection=True`. It reads `Models/Movie.cs`, where `Price` carries `[Column(TypeName = "decimal(18, 2)")]` and `ReleaseDate` is a `DateOnly`, the three files under `Migrations` with their snapshot, `Data/SeedData.cs`, and every component that queries the context, starting with `Components/Pages/MoviePages/Index.razor`.

The code change is small. The package reference becomes `Npgsql.EntityFrameworkCore.PostgreSQL` on the 10.0 line to match the other EF Core packages, `UseSqlServer` becomes `UseNpgsql`, and the connection string takes the `Host`, `Database`, `Username` and `Password` form. The agent does not write a password into `appsettings.json`; it leaves a development default without one and documents the `ConnectionStrings__BlazorWebAppMoviesContext` environment variable. The other packages in the project file, the QuickGrid adapter, the EF Core tools and the developer exception page filter, are provider-neutral and stay.

The migrations cannot be carried over, and the agent explains why with the lines that prove it. `InitialCreate` declares `nvarchar(max)` columns, a type PostgreSQL does not have, and marks `Id` with the `SqlServer:Identity` annotation, which another provider ignores, so even an edited copy would create a key column that never generates values. The snapshot calls `SqlServerModelBuilderExtensions.UseIdentityColumns`. So the three migrations and the snapshot are deleted and `dotnet ef migrations add InitialCreate` is run against the new provider, producing one migration with PostgreSQL column types and an identity column. The pull request states plainly that this resets migration history: an existing SQL Server database keeps its data until someone moves it, and the description gives the order for that, load tables with their explicit ids and then advance each identity sequence past the highest one.

Then come the differences that compile and still change behaviour. The search box on `/movies` filters with `Title.Contains(titleFilter)`. Under SQL Server's default collation that matched without regard to case; PostgreSQL compares case-sensitively, so typing `mad` stops finding Mad Max. The agent changes the filter to `EF.Functions.ILike` with the wildcard characters in the input escaped, and shows the difference before and after. It notes that EF Core creates the table as `"Movie"` with its capital letter, so hand-written SQL has to quote it. To verify, it installs PostgreSQL in the sandbox with apt, creates a role and a database, runs `dotnet ef database update`, starts the app so `SeedData` inserts its five films, and uses the sandbox's browser to list, search in lower case, create, edit and delete a movie, then prints the table definition with `psql`.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Migrate this Blazor Web App from SQL Server to PostgreSQL. Read the .csproj, Program.cs, appsettings.json, appsettings.Development.json, Models, Data, the Migrations folder and every component that uses the DbContext first. Replace the SQL Server provider package with Npgsql.EntityFrameworkCore.PostgreSQL on the same major as the other EF Core packages, change UseSqlServer to UseNpgsql and rewrite the connection string in Host, Database, Username, Password form with no password committed; document the ConnectionStrings environment variable instead. Explain, quoting the lines, why the existing migrations cannot run on PostgreSQL, then delete them with the snapshot and generate one new initial migration. Find every query whose result depends on SQL Server's case-insensitive collation, starting with the title filter on the movies index page, and make it case-insensitive on PostgreSQL with user input escaped. Install PostgreSQL in the sandbox, create a database, run dotnet ef database update, start the app, and in the browser list, search in lower case, create, edit and delete a movie; print the table definition with psql. Write the steps for moving existing data, including resetting identity sequences, into the pull request. Open one pull request with the commands and their output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes the project file, `Program.cs`, `appsettings.json` and `Index.razor`, deletes the three SQL Server migrations and their snapshot, and adds one new migration with its own snapshot. The description has four parts: the reason the old migrations were replaced, with the offending lines quoted; the output of `dotnet ef database update` and the table definition `psql` printed, showing the identity column, the bounded text columns and `numeric(18,2)` for the price; screenshots of the movie list, a lower-case search that finds results, and a create, edit and delete; and a data-move checklist for teams with a database to bring across.

A reviewer compares the generated migration with the model, attribute by attribute, since from now on it is the schema's source of truth. They check that no credential is committed, and that the case-insensitive filter escapes `%` and `_` so a user cannot widen a search by typing them. If the team would sooner keep exact SQL Server semantics for some column, a case-insensitive collation or the `citext` type is the alternative, and the description says where that would go.

What the run does not do is touch a real database. It proves the app against an empty PostgreSQL instance in its sandbox; copying production data and cutting over are steps for the people who own that data, with the checklist as a starting point.

## Run it on every Linear issue moved to In Progress

A team moving several apps tracks each as a Linear issue and lets the board start the work. An automation in the app's Project takes a `linear` trigger on `linear.issue.state_changed` with two entries in `states`: the planning column mapped to `plan`, the in-progress column mapped to `exec`. Moving an issue into the first starts a read-only run that posts its plan as a comment on the issue: which files change, which queries depend on collation, what the new migration will contain. Moving it into the second starts the run that opens the pull request.

The trigger needs a Linear connection for the automation's runner and fires only when the person who moved the issue is in your Rush org. It adds the issue after the saved prompt and fills in nothing, so anything specific to one app, such as a schema name, belongs in the issue's description where the agent reads it.

## Why run it on Rush?

The risky part of this migration is not the three lines that change in `Program.cs`. It is the behaviour nobody wrote down because SQL Server supplied it: case-insensitive matching, identity semantics, type names. Finding those means running the app against a real PostgreSQL and using it, and the agent does that in its own sandbox, with a database it installs there and a browser it drives, so the pull request shows the search working and the schema as created.

A developer could do the same on a laptop after installing a database server and remembering to clean up. Handing it to a run means the environment is disposable, the commands and their output are on record, and the plan can be reviewed on the issue before any code changes. When several apps need the same move, each gets its own run in its own sandbox, and each pull request reflects that app's own model and queries.

## Frequently asked questions

### Can I keep my existing EF Core migrations?

Not usefully. Migrations store provider-specific column types and annotations, so ones generated for SQL Server either fail on PostgreSQL or create a subtly wrong schema. The usual path is a fresh initial migration for the new provider, which is what this run produces.

### Does it move the data too?

No. It changes the code and schema definition and proves them on an empty database. The pull request includes the steps for copying data, the part most often missed being the identity sequences, which must be advanced after rows are loaded with explicit ids.

### Why did my search become case-sensitive on PostgreSQL?

SQL Server's default collations compare text without regard to case, and PostgreSQL's do not. A LINQ `Contains` translates to a case-sensitive match there. The agent finds such queries and rewrites them with `ILike`, or you can choose a case-insensitive collation or `citext` for the column.

### Will the table and column names change?

Not unless you ask. EF Core keeps the names from the model, so the table is `Movie` with a capital letter and needs double quotes in hand-written SQL. If you want lower-case snake_case names, the agent can add a naming convention in the same pull request before the migration is generated.

## More Blazor jobs

- [Review Pull Requests on a Blazor Web App](https://getrush.ai/run/review-pull-requests/blazor/)
- [Write bUnit Tests for a Blazor Web App](https://getrush.ai/run/write-bunit-tests/blazor/)
- [Write Playwright Tests for a Blazor Web App](https://getrush.ai/run/write-playwright-tests/blazor/)

## More jobs like this: Turn a Linear label into a PR

- [Migrate a Streamlit App to the Anthropic Messages API from a Linear Issue](https://getrush.ai/run/migrate-to-anthropic-messages-api/streamlit/)
- [Migrate a Go CLI From urfave/cli v1 to v2](https://getrush.ai/run/migrate-urfave-cli-v1-to-v2/urfave-cli/)
- [Migrate a Vue 3 App From Vuex to Pinia](https://getrush.ai/run/migrate-vuex-to-pinia/vuex/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
