-
Notifications
You must be signed in to change notification settings - Fork 73
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
creator as non-classic data object #161
Draft
abaevbog
wants to merge
13
commits into
zotero:master
Choose a base branch
from
abaevbog:classic_data_objects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9a15ff7
creator as non-classic data object
abaevbog 0561025
small libraryID fix
abaevbog e03e1dc
bulk-insert new creators + minor cleanup
abaevbog 170704d
store all data in itemCreators table
abaevbog dd18ed3
php db migration script + use old files in autoload
abaevbog 422ac13
removed typo from header
abaevbog baf5c93
removing unused code, prevent updating unchanged creators
abaevbog 8a25c08
removing tags as classic data objects - in progress
abaevbog ed68a2e
tag tests passing, move old model files
abaevbog ea9030c
itemTags primary key including itemID
abaevbog 327f68e
final cleanup, tests passing
abaevbog 2956830
moved checking of previously existing items outside of the loop
abaevbog 938f1fe
no creatorID, added key to itemTags, tag insert performace improvemen…
abaevbog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
misc/db-updates/2023-07-17/creatorsAsNonClassicDataObjects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/local/bin/php -d mysqlnd.net_read_timeout=86400 | ||
<?php | ||
set_include_path("../../../include"); | ||
require("header.inc.php"); | ||
|
||
$shardHostID = $argv[1]; | ||
$startShard = $argv[2]; | ||
$stopShard = $argv[3]; | ||
|
||
Z_Core::$debug = true; | ||
|
||
$shardIDs = Zotero_DB::columnQuery("SELECT shardID FROM shards WHERE shardHostID=? AND shardID >= ? AND shardID <= ? ORDER BY shardID", [$shardHostID, $startShard, $stopShard]); | ||
foreach ($shardIDs as $shardID) { | ||
echo "Shard: $shardID\n"; | ||
|
||
echo "Setting shard to readonly\n"; | ||
Zotero_DB::query("UPDATE shards SET state='readonly' WHERE shardID=?", $shardID); | ||
|
||
echo "Waiting 60 seconds for requests to stop\n"; | ||
sleep(60); | ||
|
||
// Creators | ||
echo "Migrating creators\n"; | ||
// Drop foreign key constraint | ||
Zotero_Admin_DB::query("ALTER TABLE `itemCreators` DROP CONSTRAINT `itemCreators_ibfk_1`", false, $shardID); | ||
Zotero_Admin_DB::query("ALTER TABLE `itemCreators` DROP CONSTRAINT `itemCreators_ibfk_2`", false, $shardID); | ||
|
||
// Create new itemCreators table | ||
Zotero_Admin_DB::query("CREATE TABLE `itemCreatorsNew` (`itemID` BIGINT UNSIGNED NOT NULL, `firstName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, `lastName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, `fieldMode` tinyint(1) UNSIGNED DEFAULT NULL, `creatorTypeID` smallint(5) UNSIGNED NOT NULL, `orderIndex` smallint(5) UNSIGNED NOT NULL, PRIMARY KEY (`itemID`, `orderIndex`)) ENGINE=InnoDB DEFAULT CHARSET=utf8", false, $shardID); | ||
|
||
// Add foreign key to item constraint | ||
Zotero_Admin_DB::query("ALTER TABLE `itemCreatorsNew` ADD CONSTRAINT `itemCreators_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE", false, $shardID); | ||
|
||
// Populate new table with data | ||
Zotero_Admin_DB::query("INSERT INTO itemCreatorsNew (firstName, lastName, fieldMode, itemID, creatorTypeID, orderIndex ) SELECT firstName, lastName, fieldMode, itemID, creatorTypeID, orderIndex from creators INNER JOIN itemCreators USING (creatorID)", false, $shardID); | ||
|
||
// Drop old creators tables | ||
Zotero_Admin_DB::query("DROP TABLE itemCreators", false, $shardID); | ||
Zotero_Admin_DB::query("DROP TABLE creators", false, $shardID); | ||
|
||
// Rename old itemCreators table | ||
Zotero_Admin_DB::query("RENAME TABLE itemCreatorsNew TO itemCreators", false, $shardID); | ||
|
||
// Tags | ||
echo "Migrating tags\n"; | ||
// Drop foreign key constraint | ||
Zotero_Admin_DB::query("ALTER TABLE `itemTags` DROP CONSTRAINT `itemTags_ibfk_1`", false, $shardID); | ||
Zotero_Admin_DB::query("ALTER TABLE `itemTags` DROP CONSTRAINT `itemTags_ibfk_2`", false, $shardID); | ||
|
||
// Create new itemTags table | ||
Zotero_Admin_DB::query("CREATE TABLE `itemTagsNew` ( `tagID` BIGINT UNSIGNED NOT NULL, `itemID` BIGINT UNSIGNED NOT NULL, `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, `type` tinyint(1) unsigned NOT NULL DEFAULT '0', `version` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`tagID`, `itemID`), KEY `nameType` (`name`, `type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8", false, $shardID); | ||
|
||
// Add foreign key to item constraint | ||
Zotero_Admin_DB::query("ALTER TABLE `itemTagsNew` ADD CONSTRAINT `itemTags_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE", false, $shardID); | ||
|
||
// Populate new table with data | ||
Zotero_Admin_DB::query("INSERT INTO itemTagsNew (tagID, itemID, name, type, version) SELECT tagID, itemID, name, type, version from tags INNER JOIN itemTags USING (tagID)", false, $shardID); | ||
|
||
// Drop old creators tables | ||
Zotero_Admin_DB::query("DROP TABLE itemTags", false, $shardID); | ||
Zotero_Admin_DB::query("DROP TABLE tags", false, $shardID); | ||
|
||
// Rename old itemTags table | ||
Zotero_Admin_DB::query("RENAME TABLE itemTagsNew TO itemTags", false, $shardID); | ||
|
||
|
||
echo "Bringing shard back up\n"; | ||
Zotero_DB::query("UPDATE shards SET state='up' WHERE shardID=?", $shardID); | ||
echo "Done with shard $shardID\n\n"; | ||
sleep(1); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need all the schema changes here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,7 +330,7 @@ CREATE TABLE `syncDeleteLogIDs` ( | |
|
||
CREATE TABLE `syncDeleteLogKeys` ( | ||
`libraryID` int(10) unsigned NOT NULL, | ||
`objectType` enum('collection','creator','item','relation','search','setting','tag','tagName') NOT NULL, | ||
`objectType` enum('collection','item','relation','search','setting','tag','tagName') NOT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
`key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, | ||
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`version` int(10) unsigned NOT NULL DEFAULT '1', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be empty in the committed code