20260323003506_Migration_20260323083440.cs
3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Rcs.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class Migration_20260323083440 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(
"""
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
) THEN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
AND column_name = 'curve_type'
) THEN
ALTER TABLE map_edges
ADD COLUMN curve_type integer NOT NULL DEFAULT 0;
END IF;
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
AND column_name = 'is_curve'
) THEN
UPDATE map_edges
SET curve_type = CASE
WHEN is_curve = FALSE THEN 0
WHEN is_curve = TRUE
AND radius IS NOT NULL
AND center_x IS NOT NULL
AND center_y IS NOT NULL THEN 1
ELSE 2
END;
ALTER TABLE map_edges
DROP COLUMN is_curve;
END IF;
END IF;
END
$$;
""");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(
"""
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
) THEN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
AND column_name = 'is_curve'
) THEN
ALTER TABLE map_edges
ADD COLUMN is_curve boolean NOT NULL DEFAULT FALSE;
END IF;
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'map_edges'
AND column_name = 'curve_type'
) THEN
UPDATE map_edges
SET is_curve = CASE
WHEN curve_type = 0 THEN FALSE
ELSE TRUE
END;
ALTER TABLE map_edges
DROP COLUMN curve_type;
END IF;
END IF;
END
$$;
""");
}
}
}