forked from supabase/wrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
271 lines (255 loc) · 7.16 KB
/
init.sql
File metadata and controls
271 lines (255 loc) · 7.16 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
-- OpenAPI FDW example: CarAPI (Vehicle Data)
-- Free demo dataset (2015-2020 vehicles), no auth required.
-- See: https://carapi.app/api
-- Note: fdw_package_url uses file:// for local Docker testing. In production, use the
-- GitHub release URL: https://github.com/supabase/wrappers/releases/download/wasm_openapi_fdw_v0.2.0/openapi_fdw.wasm
-- Create supabase_admin role if it doesn't exist (required by wrappers extension)
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'supabase_admin') THEN
CREATE ROLE supabase_admin WITH SUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD 'postgres';
END IF;
END
$$;
create schema if not exists extensions;
create extension if not exists wrappers with schema extensions;
set search_path to public, extensions;
create foreign data wrapper wasm_wrapper
handler wasm_fdw_handler
validator wasm_fdw_validator;
-- ============================================================
-- Server 1: carapi — Main CarAPI server (no auth, free demo)
-- Response format: {"collection": {...pagination...}, "data": [...]}
-- The FDW auto-detects the "data" wrapper key.
-- ============================================================
create server carapi
foreign data wrapper wasm_wrapper
options (
fdw_package_url 'file:///openapi_fdw.wasm',
fdw_package_name 'supabase:openapi-fdw',
fdw_package_version '0.2.0',
base_url 'https://carapi.app/api'
);
-- ============================================================
-- Server 2: carapi_debug — Same API with debug output
-- ============================================================
create server carapi_debug
foreign data wrapper wasm_wrapper
options (
fdw_package_url 'file:///openapi_fdw.wasm',
fdw_package_name 'supabase:openapi-fdw',
fdw_package_version '0.2.0',
base_url 'https://carapi.app/api',
debug 'true'
);
-- ============================================================
-- Server 3: carapi_import — With spec_url for IMPORT FOREIGN SCHEMA
-- ============================================================
create server carapi_import
foreign data wrapper wasm_wrapper
options (
fdw_package_url 'file:///openapi_fdw.wasm',
fdw_package_name 'supabase:openapi-fdw',
fdw_package_version '0.2.0',
base_url 'https://carapi.app/api',
spec_url 'https://carapi.app/swagger.json'
);
-- ============================================================
-- Table 1: makes
-- All car manufacturers (paginated)
-- Features: auto-detected "data" wrapper, page-based pagination
-- ============================================================
create foreign table makes (
id integer,
name text,
attrs jsonb
)
server carapi
options (
endpoint '/makes/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 2: models
-- Car models filtered by make and year
-- Features: query param pushdown (make, year), pagination
-- ============================================================
create foreign table models (
id integer,
make_id integer,
year integer,
make text,
name text,
attrs jsonb
)
server carapi
options (
endpoint '/models/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 3: trims
-- Trim levels with MSRP and descriptions
-- Features: query pushdown (year, make, model), pricing data,
-- integer types, timestamptz coercion
-- ============================================================
create foreign table trims (
id integer,
make_id integer,
model_id integer,
year integer,
make text,
model text,
submodel text,
trim text,
description text,
msrp integer,
invoice integer,
created timestamptz,
modified timestamptz,
attrs jsonb
)
server carapi
options (
endpoint '/trims/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 4: bodies
-- Vehicle body dimensions and specs
-- Features: query pushdown, physical measurements (text for
-- decimal strings), integer for counts/weights
-- ============================================================
create foreign table bodies (
id integer,
year integer,
make text,
model text,
submodel text,
trim text,
type text,
doors integer,
length text,
width text,
height text,
wheel_base text,
ground_clearance text,
cargo_capacity text,
curb_weight integer,
seats integer,
attrs jsonb
)
server carapi
options (
endpoint '/bodies/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 5: engines
-- Engine specifications and performance data
-- Features: query pushdown, horsepower/torque as integers,
-- engine type, fuel type, drive type, transmission
-- ============================================================
create foreign table engines (
id integer,
year integer,
make text,
model text,
submodel text,
trim text,
engine_type text,
fuel_type text,
cylinders text,
size text,
horsepower_hp integer,
horsepower_rpm integer,
torque_ft_lbs integer,
torque_rpm integer,
valves integer,
valve_timing text,
cam_type text,
drive_type text,
transmission text,
attrs jsonb
)
server carapi
options (
endpoint '/engines/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 6: mileages
-- Fuel economy and range data (MPG, tank capacity, EV stats)
-- Features: query pushdown, EPA mileage ratings, range data
-- ============================================================
create foreign table mileages (
id integer,
year integer,
make text,
model text,
submodel text,
trim text,
fuel_tank_capacity text,
combined_mpg integer,
epa_city_mpg integer,
epa_highway_mpg integer,
range_city integer,
range_highway integer,
attrs jsonb
)
server carapi
options (
endpoint '/mileages/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 7: exterior_colors
-- Paint colors with RGB values
-- Features: query pushdown, color name + RGB string
-- ============================================================
create foreign table exterior_colors (
id integer,
year integer,
make text,
model text,
submodel text,
trim text,
color text,
rgb text,
attrs jsonb
)
server carapi
options (
endpoint '/exterior-colors/v2',
rowid_column 'id'
);
-- ============================================================
-- Table 8: obd_codes
-- OBD-II diagnostic trouble codes
-- Features: small dataset on free tier, code + description
-- ============================================================
create foreign table obd_codes (
code text,
description text,
attrs jsonb
)
server carapi
options (
endpoint '/obd-codes',
rowid_column 'code'
);
-- ============================================================
-- Table 9: makes_debug
-- Same as makes but on the debug server
-- Features: debug output in INFO messages
-- ============================================================
create foreign table makes_debug (
id integer,
name text,
attrs jsonb
)
server carapi_debug
options (
endpoint '/makes/v2',
rowid_column 'id'
);