Revoke cards by cardIndex and drop cardId uniqueness
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s
This commit is contained in:
@@ -46,27 +46,9 @@ class IssuedCardSchemaFix(
|
||||
Int::class.java
|
||||
) ?: 0
|
||||
|
||||
if (uniqueIndexExists == 0) {
|
||||
logger.info("Removing duplicate issued_card rows by property_id + card_id")
|
||||
jdbcTemplate.execute(
|
||||
"""
|
||||
with ranked as (
|
||||
select id,
|
||||
row_number() over (
|
||||
partition by property_id, lower(card_id)
|
||||
order by issued_at desc, id desc
|
||||
) as rn
|
||||
from issued_card
|
||||
where card_id is not null
|
||||
)
|
||||
delete from issued_card
|
||||
where id in (select id from ranked where rn > 1)
|
||||
""".trimIndent()
|
||||
)
|
||||
logger.info("Creating unique index on issued_card(property_id, lower(card_id))")
|
||||
jdbcTemplate.execute(
|
||||
"create unique index if not exists idx_issued_card_property_card_id_unique on issued_card (property_id, lower(card_id))"
|
||||
)
|
||||
if (uniqueIndexExists > 0) {
|
||||
logger.info("Dropping unique index on issued_card(property_id, lower(card_id))")
|
||||
jdbcTemplate.execute("drop index if exists idx_issued_card_property_card_id_unique")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user