Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Knex } from 'knex'

export async function run(knex: Knex): Promise<void> {
await knex.transaction(async trx => {
await trx.raw(`
UPDATE tombos
SET local_coleta_id = NULL
FROM locais_coleta lc
WHERE tombos.local_coleta_id = lc.id
AND (lc.descricao IS NULL OR TRIM(lc.descricao) = '')
`)

await trx.raw(`
DELETE FROM locais_coleta lc
WHERE (lc.descricao IS NULL OR TRIM(lc.descricao) = '')
AND NOT EXISTS (
SELECT 1 FROM tombos t WHERE t.local_coleta_id = lc.id
)
`)
})
}
Loading