Skip to content

Commit

Permalink
Merge pull request #37 from ko4life-net/migrate-text-columns
Browse files Browse the repository at this point in the history
Migrate database schema to modern types and improve string handling
  • Loading branch information
stevewgr committed Nov 19, 2024
2 parents 26ab523 + 6e9f29c commit 890f05e
Show file tree
Hide file tree
Showing 4 changed files with 6,287 additions and 0 deletions.
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

0 comments on commit 890f05e

Please sign in to comment.