Skip to content

Commit

Permalink
rework polls and fact checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesNakayama committed Sep 16, 2024
1 parent 9cdd6a0 commit 1b69696
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions migrations/2024-09-16-artefacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { type Kysely, sql } from 'kysely'

export async function up(db: Kysely<any>): Promise<void> {
await db.transaction().execute(async trx => {
/*
* Create `Artifact` and `Quote` tables
*/

await sql`
create table Artefact (
id integer not null primary key autoincrement
, url text not null unique
, description text default null
, createdAt integer not null default (unixepoch('subsec')*1000)
)
`.execute(trx)

// -- The `Quote` table is for the verbatim quote pasted into Jabble.

await sql`
create table Quote (
id integer not null primary key autoincrement
, artefactId integer not null references Artefact(id)
, quote text not null
, createdAt integer not null default (unixepoch('subsec')*1000)
)
`.execute(trx)

/*
* Preserve `ClaimToArtifact` relation
*/

await sql`
insert into Artefact (
url
, createdAt
)
select
origin
, min(createdAt) as createdAt
from ClaimContext
where origin is not null
and origin <> ''
group by origin
`.execute(trx)

await sql`
create table ClaimToArtefact (
claimId integer not null references Claim(Id)
, artefactId integer not null references Artefact(id)
, primary key (claimId, artefactId)
)
`.execute(trx)

await sql`
insert into ClaimToArtefact (
claimId
, artefactId
)
select
a.id as artefactId
, c2cc.claimid as claimId
from claimcontext cc
join artefact a
on a.url = cc.origin
join claimtoclaimcontext c2cc
on cc.id = c2cc.contextId
where origin <> ''
and origin is not null
`.execute(trx)

/*
* Remove contextId from `Poll`
*/

// -- We need to recreate the table because contextId is in the primary key
// -- of the `Poll` table.

await sql`
alter table Poll
rename to PollDeprecated__TMP
`.execute(trx)

await sql`
create table Poll (
claimId integer not null references Claim(Id)
, postId integer not null references Post(id)
, pollType text not null
, primary key (claimId)
)
`.execute(trx)

await sql`
insert into Poll (
claimId
, postId
, pollType
)
select
claimId
, postId
, pollType
from PollDeprecated__TMP
`.execute(trx)

await sql`
drop table PollDeprecated__TMP
`.execute(trx)

})
}

0 comments on commit 1b69696

Please sign in to comment.