Skip to content

Commit 8524167

Browse files
committed
fix: remove functions and add relationships
1 parent 46422a5 commit 8524167

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

scripts/migrations/src/migrations/20241029T120000_initial.ts

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ export async function up(db: Kysely<any>): Promise<void> {
207207
.addColumn("tags", sql`text[]`)
208208

209209
.addPrimaryKeyConstraint("applications_pkey", ["chainId", "roundId", "id"])
210+
.addForeignKeyConstraint(
211+
"applications_projects_fkey",
212+
["chainId", "projectId"],
213+
"projects",
214+
["chainId", "id"],
215+
(cb) => cb.onDelete("cascade"),
216+
)
217+
210218
.addForeignKeyConstraint(
211219
"applications_rounds_fkey",
212220
["roundId", "chainId"],
@@ -290,28 +298,8 @@ export async function up(db: Kysely<any>): Promise<void> {
290298
.addUniqueConstraint("unique_v2ProjectId", ["v2ProjectId"])
291299
.execute();
292300

293-
// Computed fields
301+
// Project search function
294302
await sql`
295-
create function ${ref("applications_project")}(a ${ref(
296-
"applications",
297-
)} ) returns ${ref("projects")} as $$
298-
select *
299-
from ${ref("projects")}
300-
where id = a.project_id
301-
and (chain_id = a.chain_id or true)
302-
order by
303-
case when chain_id = a.chain_id then 0 else 1 end,
304-
id
305-
limit 1;
306-
$$ language sql stable;
307-
308-
create function ${ref("projects_applications")}(p ${ref(
309-
"projects",
310-
)} ) returns setof ${ref("applications")} as $$
311-
select *
312-
from ${ref("applications")}
313-
where project_id = p.id;
314-
$$ language sql stable;
315303
316304
create function ${ref("search_projects")}(search_term text)
317305
returns setof ${ref("projects")} as $$
@@ -320,16 +308,6 @@ export async function up(db: Kysely<any>): Promise<void> {
320308
where to_tsvector(name) @@ to_tsquery(search_term)
321309
order by ts_rank_cd(to_tsvector(name), to_tsquery(search_term)) desc;
322310
$$ language sql stable;
323-
324-
create function ${ref("applications_canonical_project")}(a ${ref(
325-
"applications",
326-
)} ) returns ${ref("projects")} as $$
327-
select *
328-
from ${ref("projects")}
329-
where id = a.project_id
330-
and project_type = 'canonical'
331-
limit 1;
332-
$$ language sql stable;
333311
`.execute(db);
334312
}
335313

0 commit comments

Comments
 (0)