Skip to content
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

Migrate database schema to modern types and improve string handling #37

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions src/migration/0022_migrate_text_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- Migrates legacy text columns to varchar(3000), which should be big enough to store really long NPC paths
-- Also organized K_NPCPOS table

CREATE TABLE [dbo].[K_NPCPOS_TMP] (
[ZoneID] [smallint] NOT NULL,
[NpcID] [int] NOT NULL,
[ActType] [tinyint] NOT NULL,
[RegenType] [tinyint] NULL,
[DungeonFamily] [tinyint] NULL,
[SpecialType] [tinyint] NULL,
[TrapNumber] [tinyint] NULL,
[LeftX] [int] NOT NULL,
[TopZ] [int] NOT NULL,
[RightX] [int] NOT NULL,
[BottomZ] [int] NOT NULL,
[LimitMinX] [int] NULL,
[LimitMinZ] [int] NULL,
[LimitMaxX] [int] NULL,
[LimitMaxZ] [int] NULL,
[NumNPC] [tinyint] NOT NULL,
[RegTime] [smallint] NOT NULL,
[DotCnt] [tinyint] NOT NULL,
[path] [varchar](3000) NULL -- Changed from ntext to varchar(3000)
);

INSERT INTO [dbo].[K_NPCPOS_TMP] (
[ZoneID], [NpcID], [ActType], [RegenType], [DungeonFamily], [SpecialType], [TrapNumber],
[LeftX], [TopZ], [RightX], [BottomZ], [LimitMinX], [LimitMinZ], [LimitMaxX], [LimitMaxZ],
[NumNPC], [RegTime], [DotCnt], [path]
)
SELECT
[ZoneID],
[NpcID],
[ActType],
[RegenType],
[DungeonFamily],
[SpecialType],
[TrapNumber],
[LeftX],
[TopZ],
[RightX],
[BottomZ],
[LimitMinX],
[LimitMinZ],
[LimitMaxX],
[LimitMaxZ],
[NumNPC],
[RegTime],
[DotCnt],
CAST([path] AS varchar(3000)) -- Convert ntext to varchar
FROM [dbo].[K_NPCPOS];

DROP TABLE [dbo].[K_NPCPOS];
EXEC sp_rename 'dbo.K_NPCPOS_TMP', 'K_NPCPOS';

-- Drop unused text column
ALTER TABLE [dbo].[K_NPC] DROP COLUMN [Obs];
Loading