Skip to content

Commit dfa5a11

Browse files
authored
chore: fixed migration (#1767)
* chore: fixed migration * chore: fixed
1 parent 0a82fed commit dfa5a11

3 files changed

Lines changed: 307 additions & 26 deletions

File tree

admin/backend/prisma/schema.prisma

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ model recreation_structure {
224224

225225
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
226226
model recreation_structure_code {
227-
structure_code Int @id @default(autoincrement())
228-
description String? @db.VarChar(120)
229-
updated_at DateTime? @default(now()) @db.Timestamp(6)
230-
sys_period Unsupported("tstzrange") @default(dbgenerated("tstzrange(CURRENT_TIMESTAMP, NULL::timestamp with time zone)"))
231-
recreation_structure recreation_structure[]
232-
recreation_asset_recreation_asset_recreation_structure_codeTorecreation_structure_code recreation_asset[] @relation("recreation_asset_recreation_structure_codeTorecreation_structure_code")
227+
structure_code Int @id @default(autoincrement())
228+
description String? @db.VarChar(120)
229+
updated_at DateTime? @default(now()) @db.Timestamp(6)
230+
sys_period Unsupported("tstzrange") @default(dbgenerated("tstzrange(CURRENT_TIMESTAMP, NULL::timestamp with time zone)"))
231+
recreation_asset_recreation_asset_recreation_structure_codeTorecreation_structure_code recreation_asset[] @relation("recreation_asset_recreation_structure_codeTorecreation_structure_code")
232+
recreation_structure recreation_structure[]
233233
234234
@@schema("rst")
235235
}
@@ -1522,6 +1522,33 @@ model recreation_asset_repair_history {
15221522
@@schema("rst")
15231523
}
15241524

1525+
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
1526+
model recreation_asset_code {
1527+
asset_code Int @id @default(autoincrement())
1528+
description String? @db.VarChar(120)
1529+
updated_at DateTime? @default(now()) @db.Timestamp(6)
1530+
updated_by String?
1531+
created_at DateTime? @default(now()) @db.Timestamp(6)
1532+
created_by String?
1533+
sys_period Unsupported("tstzrange") @default(dbgenerated("tstzrange(CURRENT_TIMESTAMP, NULL::timestamp with time zone)"))
1534+
1535+
@@schema("rst")
1536+
}
1537+
1538+
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
1539+
model recreation_asset_code_history {
1540+
asset_code Int
1541+
description String? @db.VarChar(120)
1542+
updated_at DateTime? @db.Timestamp(6)
1543+
updated_by String?
1544+
created_at DateTime? @db.Timestamp(6)
1545+
created_by String?
1546+
sys_period Unsupported("tstzrange")
1547+
1548+
@@ignore
1549+
@@schema("rst")
1550+
}
1551+
15251552
/// The underlying view does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
15261553
/// This view or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
15271554
view recreation_resource_type_view_admin {

migrations/rst/sql/V1.1.82__recreation_asset.sql

Lines changed: 110 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,115 @@
1-
-- Seed a "Campsite" structure type. Campsites are modelled as assets (parent of other
2-
-- assets via parent_id). This type does not exist in FTA, so the FTA structure_code sync
3-
-- will never create it; seed it here (insert-only sync leaves it untouched).
4-
insert into rst.recreation_structure_code (description)
5-
select 'Campsite'
6-
where not exists (
7-
select 1 from rst.recreation_structure_code
8-
where lower(description) = 'campsite'
1+
2+
-- recreation_asset_code must be created before recreation_asset (FK dependency)
3+
create table rst.recreation_asset_code
4+
(
5+
asset_code serial primary key,
6+
description varchar(120)
97
);
108

9+
comment on table rst.recreation_asset_code is 'Codes describing the classification type of an individual recreation asset (e.g. Campsite, Table, Toilet). Not FTA-synced; managed internally.';
10+
comment on column rst.recreation_asset_code.asset_code is 'Surrogate primary key for the asset type code.';
11+
comment on column rst.recreation_asset_code.description is 'Description of the asset type.';
12+
13+
insert into rst.recreation_asset_code (description)
14+
values
15+
('Table - log'),
16+
('Table - wheelchair accessible'),
17+
('Toilet - wood'),
18+
('Toilet - wheelchair accessible'),
19+
('Fire ring'),
20+
('Litter barrel - 45 gallon'),
21+
('Barrel shelters'),
22+
('Parking - unimproved'),
23+
('Parking - unsurfaced'),
24+
('Parking - spaces gravel'),
25+
('Parking - spaces pavement'),
26+
('Parking - wheelchair accessible'),
27+
('Registration post'),
28+
('Boat launch - cartop (unimproved)'),
29+
('Boat launch - unimproved'),
30+
('Boat launch - gravel'),
31+
('Boat launch - concrete'),
32+
('Safety barrier'),
33+
('Signs'),
34+
('Sign - stop'),
35+
('Sign - directional (facility)'),
36+
('Entrance kiosk'),
37+
('Sign shelter'),
38+
('Shelter (cabins, warming huts)'),
39+
('Shelter - wheelchair accessible'),
40+
('Traffic counter'),
41+
('Dock wharf'),
42+
('Dock wharf - wheelchair accessible'),
43+
('Bench'),
44+
('Boardwalk'),
45+
('Bridge - foot (>6M)'),
46+
('Bridge - foot (<6M)'),
47+
('Bridge - wheelchair accessible'),
48+
('Corral - firewood'),
49+
('Corral - firewood - wheelchair accessible'),
50+
('Corral - horse'),
51+
('Hitching rail'),
52+
('Observation tower'),
53+
('Viewing platform'),
54+
('Viewing blinds'),
55+
('Trail'),
56+
('Trail - wheelchair accessible'),
57+
('Tent pad'),
58+
('Vehicle space'),
59+
('Total length of associated roads'),
60+
('Dock pier'),
61+
('Dock floating'),
62+
('Table - concrete'),
63+
('Table - metal'),
64+
('Toilet - metal'),
65+
('Toilet - concrete'),
66+
('Toilet - solar composting'),
67+
('Litter barrel - bear proof single'),
68+
('Litter barrel - bear proof double'),
69+
('Gate'),
70+
('In-site road'),
71+
('Culvert'),
72+
('Fencing - russell'),
73+
('Stairs'),
74+
('Pools and tubs - hotsprings'),
75+
('Fish cleaning station'),
76+
('Bridge - vehicle'),
77+
('Bridge - foot (suspension)'),
78+
('Cable car'),
79+
('Helipad'),
80+
('Log boom'),
81+
('Bear cache'),
82+
('Fencing - barb wire'),
83+
('Fencing - log'),
84+
('Fencing - chain link'),
85+
('Sign shelter - small'),
86+
('Sign shelter - large'),
87+
('Sign - 3 blade'),
88+
('Sign - highway'),
89+
('Barrier - no post'),
90+
('Barrier - lock block'),
91+
('Gate - single'),
92+
('Mooring buoy'),
93+
('Registration box'),
94+
('Barrier - rock'),
95+
('Fencing - strand'),
96+
('Gate - double'),
97+
('Barrier - wood'),
98+
('Bridge - foot'),
99+
('Campsite');
100+
101+
select upsert_timestamp_columns('rst', 'recreation_asset_code');
102+
103+
select setup_temporal_table('rst', 'recreation_asset_code', false);
104+
105+
11106
create table rst.recreation_asset
12107
(
13108
asset_id bigint generated always as identity primary key,
14109
parent_id bigint,
15110
asset_tag varchar(50),
16111
rec_resource_id varchar(20) not null,
17-
recreation_structure_code integer not null,
112+
asset_code integer not null,
18113
asset_name varchar(200),
19114
asset_comment text,
20115
legacy_structure_id varchar(20),
@@ -36,23 +131,23 @@ create table rst.recreation_asset
36131
constraint chk_no_self_parent
37132
check (parent_id <> asset_id),
38133

39-
constraint fk_asset_struct_code
40-
foreign key (recreation_structure_code)
41-
references rst.recreation_structure_code (structure_code)
134+
constraint fk_asset_asset_code
135+
foreign key (asset_code)
136+
references rst.recreation_asset_code (asset_code)
42137
);
43138

44139
-- Performance indexes (no GiST — geometry lives in recreation_asset_geom)
45140
create index idx_recreation_asset_parent_id on rst.recreation_asset (parent_id);
46141
create index idx_recreation_asset_site on rst.recreation_asset (rec_resource_id);
47-
create index idx_recreation_asset_code on rst.recreation_asset (recreation_structure_code);
142+
create index idx_recreation_asset_code on rst.recreation_asset (asset_code);
48143

49144
comment on table rst.recreation_asset is 'Individualised asset entities with parent-child relationships (e.g., Campsite → Table). Geometry stored in recreation_asset_geom.';
50145
comment on column rst.recreation_asset.asset_id is 'Unique surrogate identifier for the individual asset.';
51146
comment on column rst.recreation_asset.parent_id is 'ID of the parent container asset (e.g., Campsite, Day Use Area, Zone). NULL if top-level.';
52147
comment on column rst.recreation_asset.asset_tag is 'Physical barcode, field tag, or campsite designation (e.g., CS-012, TBL-012-A).';
53148
comment on column rst.recreation_asset.rec_resource_id is 'FK to the parent Recreation Resource / Site (rst.recreation_resource).';
54-
comment on column rst.recreation_asset.recreation_structure_code is 'Asset classification type (FK to rst.recreation_structure_code.structure_code).';
55-
comment on column rst.recreation_asset.asset_name is 'Optional display name for the asset. UI defaults to structure_code description when null.';
149+
comment on column rst.recreation_asset.asset_code is 'Asset classification type (FK to rst.recreation_asset_code.asset_code).';
150+
comment on column rst.recreation_asset.asset_name is 'Optional display name for the asset. UI defaults to asset_code description when null.';
56151
comment on column rst.recreation_asset.asset_comment is 'Free-text note or migrated structure_name value for this asset.';
57152
comment on column rst.recreation_asset.legacy_structure_id is 'Informational string reference to the legacy aggregate recreation_structure record.';
58153
comment on column rst.recreation_asset.asset_length is 'Total length in metres (paths, boardwalks, fences, bridges).';

0 commit comments

Comments
 (0)