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
205 lines (191 loc) · 5.86 KB
/
init.sql
File metadata and controls
205 lines (191 loc) · 5.86 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
-- OpenAPI FDW example: PokéAPI
-- All queries hit the live PokéAPI (no auth required).
-- 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: pokeapi — Main PokéAPI server
-- ============================================================
create server pokeapi
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://pokeapi.co/api/v2',
page_size '20',
page_size_param 'limit'
);
-- ============================================================
-- Server 2: pokeapi_debug — Same API with debug output
-- ============================================================
create server pokeapi_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://pokeapi.co/api/v2',
page_size '20',
page_size_param 'limit',
debug 'true'
);
-- ============================================================
-- Server 3: pokeapi_import — With spec_url for IMPORT FOREIGN SCHEMA
-- ============================================================
create server pokeapi_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://pokeapi.co/api/v2',
spec_url 'https://raw.githubusercontent.com/PokeAPI/pokeapi/master/openapi.yml',
page_size '20',
page_size_param 'limit'
);
-- ============================================================
-- Table 1: pokemon
-- Paginated list of all Pokémon (~1350 items)
-- Features: offset-based pagination, auto-detected `results`
-- wrapper key, LIMIT pushdown
-- ============================================================
create foreign table pokemon (
name text,
url text,
attrs jsonb
)
server pokeapi
options (
endpoint '/pokemon',
rowid_column 'name'
);
-- ============================================================
-- Table 2: pokemon_detail
-- Single Pokémon detail via path parameter
-- Features: path param substitution (WHERE name = 'pikachu'),
-- single object response, integer/boolean coercion,
-- jsonb for complex nested data (abilities, types, etc.)
-- ============================================================
create foreign table pokemon_detail (
id integer,
name text,
height integer,
weight integer,
base_experience integer,
is_default boolean,
order_num integer,
abilities jsonb,
types jsonb,
stats jsonb,
moves jsonb,
sprites jsonb,
attrs jsonb
)
server pokeapi
options (
endpoint '/pokemon/{name}',
rowid_column 'id'
);
-- ============================================================
-- Table 3: types
-- Paginated list of all Pokémon types (21 items)
-- Features: small paginated list, fits in a single page
-- ============================================================
create foreign table types (
name text,
url text,
attrs jsonb
)
server pokeapi
options (
endpoint '/type',
rowid_column 'name'
);
-- ============================================================
-- Table 4: type_detail
-- Single type detail via path parameter
-- Features: path param, damage relations as jsonb,
-- pokemon list per type
-- ============================================================
create foreign table type_detail (
id integer,
name text,
damage_relations jsonb,
pokemon jsonb,
moves jsonb,
attrs jsonb
)
server pokeapi
options (
endpoint '/type/{name}',
rowid_column 'id'
);
-- ============================================================
-- Table 5: berries
-- Paginated list of all berries (64 items)
-- Features: offset-based pagination, auto-detected `results`
-- ============================================================
create foreign table berries (
name text,
url text,
attrs jsonb
)
server pokeapi
options (
endpoint '/berry',
rowid_column 'name'
);
-- ============================================================
-- Table 6: berry_detail
-- Single berry detail via path parameter
-- Features: path param, integer columns for growth/harvest data,
-- jsonb for firmness/flavors/natural_gift_type
-- ============================================================
create foreign table berry_detail (
id integer,
name text,
growth_time integer,
max_harvest integer,
natural_gift_power integer,
size integer,
smoothness integer,
soil_dryness integer,
firmness jsonb,
flavors jsonb,
natural_gift_type jsonb,
attrs jsonb
)
server pokeapi
options (
endpoint '/berry/{name}',
rowid_column 'id'
);
-- ============================================================
-- Table 7: pokemon_debug
-- Same as pokemon but on the debug server
-- Features: debug output in INFO messages
-- ============================================================
create foreign table pokemon_debug (
name text,
url text,
attrs jsonb
)
server pokeapi_debug
options (
endpoint '/pokemon',
rowid_column 'name'
);