-
Notifications
You must be signed in to change notification settings - Fork 0
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
report migration #9
base: develop
Are you sure you want to change the base?
Conversation
modified: database/003_insert_playerdata_dev.sql modified: database/create.sh
report_migration/report_data.sql
Outdated
UPDATE temp_batch AS tb | ||
LEFT JOIN report_sighting AS rs | ||
ON tb.reportingID = rs.reporting_id AND tb.reportedID = rs.reported_id AND tb.manual_detect = rs.manual_detect | ||
SET tb.report_sighting_id = rs.report_sighting_id; | ||
|
||
|
||
|
||
-- Debug: Check temp_batch after update | ||
-- SELECT * FROM temp_batch WHERE report_sighting_id IS NULL; | ||
|
||
-- Step 4: Insert missing rows into report_sighting | ||
INSERT INTO report_sighting (reporting_id, reported_id, manual_detect) | ||
SELECT DISTINCT reportingID, reportedID, manual_detect | ||
FROM temp_batch | ||
WHERE report_sighting_id IS NULL | ||
ORDER BY reportingID, reportedID, manual_detect; | ||
|
||
-- Debug: Check rows inserted into report_sighting | ||
-- SELECT * FROM report_sighting ORDER BY report_sighting_id DESC LIMIT 10; | ||
|
||
-- Step 5: Update temp_batch with newly inserted report_sighting IDs | ||
UPDATE temp_batch AS tb | ||
JOIN report_sighting AS rs | ||
ON tb.reportingID = rs.reporting_id AND tb.reportedID = rs.reported_id AND tb.manual_detect = rs.manual_detect | ||
SET tb.report_sighting_id = rs.report_sighting_id | ||
WHERE tb.report_sighting_id IS NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you did not adopt this from migrate_report_sighting
INSERT INTO report_sighting (reporting_id, reported_id, manual_detect)
SELECT DISTINCT tb.reportingID , tb.reportedID , IFNULL(tb..manual_detect,0) from temp_batch tb
WHERE 1
AND NOT EXISTS (
SELECT 1 FROM report_sighting rs
WHERE 1
AND tb.reportingID = rs.reporting_id
AND tb.reportedID = rs.reported_id
AND IFNULL(tb.manual_detect,0) = rs.manual_detect
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 3 finds existing report_sighting_id and sets it to the temp_batch
so when step 4 mentions "WHERE report_sighting_id IS NULL" it does the same as
"AND NOT EXISTS (
SELECT 1 FROM report_sighting rs
WHERE 1
AND tb.reportingID = rs.reporting_id
AND tb.reportedID = rs.reported_id
AND IFNULL(tb.manual_detect,0) = rs.manual_detect
);"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you are correct, but is there any particular reason you went for two updates?
SELECT DISTINCT equip_head_id, equip_amulet_id, equip_torso_id, equip_legs_id, | ||
equip_boots_id, equip_cape_id, equip_hands_id, equip_weapon_id, equip_shield_id | ||
FROM temp_batch | ||
WHERE report_gear_id IS NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to commit to the update table idea you'll have to check every table first
INSERT INTO report_location (region_id, x_coord, y_coord, z_coord) | ||
SELECT DISTINCT region_id, x_coord, y_coord, z_coord | ||
FROM temp_batch | ||
WHERE report_location_id IS NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to commit to the update table idea you'll have to check every table first
…s null (Removes requirement for one less update statement)
No description provided.