Revoke cards by cardIndex and drop cardId uniqueness
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s

This commit is contained in:
androidlover5842
2026-01-28 18:24:40 +05:30
parent 914d824e51
commit 385a66d5c5
3 changed files with 7 additions and 39 deletions

View File

@@ -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")
}
}
}