@@ -207,6 +207,14 @@ export async function up(db: Kysely<any>): Promise<void> {
207
207
. addColumn ( "tags" , sql `text[]` )
208
208
209
209
. 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
+
210
218
. addForeignKeyConstraint (
211
219
"applications_rounds_fkey" ,
212
220
[ "roundId" , "chainId" ] ,
@@ -290,28 +298,8 @@ export async function up(db: Kysely<any>): Promise<void> {
290
298
. addUniqueConstraint ( "unique_v2ProjectId" , [ "v2ProjectId" ] )
291
299
. execute ( ) ;
292
300
293
- // Computed fields
301
+ // Project search function
294
302
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;
315
303
316
304
create function ${ ref ( "search_projects" ) } (search_term text)
317
305
returns setof ${ ref ( "projects" ) } as $$
@@ -320,16 +308,6 @@ export async function up(db: Kysely<any>): Promise<void> {
320
308
where to_tsvector(name) @@ to_tsquery(search_term)
321
309
order by ts_rank_cd(to_tsvector(name), to_tsquery(search_term)) desc;
322
310
$$ 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;
333
311
` . execute ( db ) ;
334
312
}
335
313
0 commit comments