Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/guides/mssqlserver/migration/databasemigration.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ NAME VERSION STATUS AGE
mssqlserver-standalone 2022-cu12 Ready 5m
```

### Create Empty Target Databases

Before you create the `MSSQLServerMigration` CR, create an empty target database for every source database that you will list in `spec.source.schema.database`. The target database name must exactly match its source database name.

The migrator applies the source schema and then copies the source data into the target. Therefore, do not create user tables or insert data in these target databases before starting the migration. For a clean retry, delete and recreate the target databases before applying a new migration CR.

For this guide, create the empty `RestaurantMigrationDB` database on the target MSSQL Server:

```sql
USE master;
GO

IF DB_ID(N'RestaurantMigrationDB') IS NULL
CREATE DATABASE [RestaurantMigrationDB];
GO
```

Verify that the target database has no user tables:

```sql
USE RestaurantMigrationDB;
GO

SELECT COUNT(*) AS UserTables FROM sys.tables WHERE is_ms_shipped = 0;
GO
```
Comment on lines +275 to +283

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

State the required verification result.

The query only displays a count. State that UserTables must be 0 and that the migration must not continue when the result is nonzero. Otherwise, a pre-existing or partially migrated RestaurantMigrationDB can be used as the target.

Suggested clarification
 SELECT COUNT(*) AS UserTables FROM sys.tables WHERE is_ms_shipped = 0;
 GO
+
+The result must be `0`. If it is not `0`, do not apply the migration CR. Delete and recreate the target database, then run this check again.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/guides/mssqlserver/migration/databasemigration.md` around lines 275 -
283, Update the target-database verification instructions after the UserTables
query to require a result of 0 and explicitly instruct readers not to continue
the migration when UserTables is nonzero.


## Apply MSSQLServerMigration CR

To migrate the database we have to create an `MSSQLServerMigration` CR. KubeDB uses [SqlPackage](https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage) for schema migration and built-in CDC for streaming changes. Below is the YAML of the `MSSQLServerMigration` CR:
Expand Down
Loading