Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] Maimai2 unique constraints #98

Open
wants to merge 2 commits into
base: v1-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion AquaNet/src/pages/UserHome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

<div class="rank">
<span>{t('UserHome.ServerRank')}</span>
<span>#{+d.user.serverRank.toLocaleString() + 1}</span>
<span>#{(d.user.serverRank + 1).toLocaleString()}</span>
</div>
</div>

Expand Down
131 changes: 131 additions & 0 deletions src/main/resources/db/migration/mariadb/V1000_25__mai2_unique.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Delete duplicate rows
DELETE FROM maimai2_user_extend
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_extend
GROUP BY user_id
);

DELETE FROM maimai2_user_option
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_option
GROUP BY user_id
);

DELETE FROM maimai2_user_character
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_character
GROUP BY user_id, character_id
);

DELETE FROM maimai2_user_map
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_map
GROUP BY user_id, map_id
);

DELETE FROM maimai2_user_login_bonus
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_login_bonus
GROUP BY user_id, bonus_id
);

DELETE FROM maimai2_user_udemae
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_udemae
GROUP BY user_id
);

DELETE FROM maimai2_user_general_data
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_general_data
GROUP BY user_id, property_key
);

DELETE FROM maimai2_user_item
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_item
GROUP BY user_id, item_id, item_kind
);

DELETE FROM maimai2_user_music_detail
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_music_detail
GROUP BY user_id, music_id, level
);

DELETE FROM maimai2_user_course
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_course
GROUP BY user_id, course_id
);

DELETE FROM maimai2_user_friend_season_ranking
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_friend_season_ranking
GROUP BY user_id, season_id
);

DELETE FROM maimai2_user_favorite
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_favorite
GROUP BY user_id, item_kind
);

DELETE FROM maimai2_user_activity
WHERE id NOT IN (
SELECT MAX(id)
FROM maimai2_user_activity
GROUP BY user_id, activity_id, kind
);

# Add unique constraint
ALTER TABLE maimai2_user_extend
ADD CONSTRAINT unique_user_extend UNIQUE (user_id);

ALTER TABLE maimai2_user_option
ADD CONSTRAINT unique_user_option UNIQUE (user_id);

ALTER TABLE maimai2_user_character
ADD CONSTRAINT unique_user_character UNIQUE (user_id, character_id);

ALTER TABLE maimai2_user_map
ADD CONSTRAINT unique_user_map UNIQUE (user_id, map_id);

ALTER TABLE maimai2_user_login_bonus
ADD CONSTRAINT unique_user_login_bonus UNIQUE (user_id, bonus_id);

ALTER TABLE maimai2_user_udemae
ADD CONSTRAINT unique_user_udemae UNIQUE (user_id);

ALTER TABLE maimai2_user_general_data
ADD CONSTRAINT unique_user_general_data UNIQUE (user_id, property_key);

ALTER TABLE maimai2_user_item
ADD CONSTRAINT unique_user_item UNIQUE (user_id, item_id, item_kind);

ALTER TABLE maimai2_user_music_detail
ADD CONSTRAINT unique_user_music_detail UNIQUE (user_id, music_id, level);

ALTER TABLE maimai2_user_course
ADD CONSTRAINT unique_user_course UNIQUE (user_id, course_id);

ALTER TABLE maimai2_user_friend_season_ranking
ADD CONSTRAINT unique_user_friend_season_ranking UNIQUE (user_id, season_id);

ALTER TABLE maimai2_user_favorite
ADD CONSTRAINT unique_user_favorite UNIQUE (user_id, item_kind);

ALTER TABLE maimai2_user_activity
ADD CONSTRAINT unique_user_activity UNIQUE (user_id, activity_id, kind);