Skip to content

Commit

Permalink
Merge "Drop wbt_type table"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 22, 2025
2 parents e80bc6f + b4582c7 commit 00c1235
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 199 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES-1.44
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Some specific notes for Wikibase 1.44 upgrades are below:
* Entries in the `wbt_term_in_lang` table will be sanitized so that the `wbtl_type_id` column
always contains `1` as the value for labels, `2` for descriptions and `3` for aliases. This
migration may take a while when running `update.php`.
* The wbt_type database table was dropped.

...

Expand Down
3 changes: 1 addition & 2 deletions docs/sql/wbt_term_in_lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Part of the @ref docs_storage_terms storage system.
**Fields:**

- wbtl_id - an auto increment field
- wbtl_type_id - reference to the [wbt_type] table
- wbtl_type_id - term type ID (`1` for a label, `2` for a description, `3` for an alias)
- wbtl_text_in_lang_id - reference to the [wbt_text_in_lang] table

```
Expand All @@ -24,5 +24,4 @@ Part of the @ref docs_storage_terms storage system.
- UNIQUE wbtl_text_in_lang_id, wbtl_type_id
- wbtl_type_id

[wbt_type]: @ref docs_sql_wbt_type
[wbt_text_in_lang]: @ref docs_sql_wbt_text_in_lang
32 changes: 0 additions & 32 deletions docs/sql/wbt_type.md

This file was deleted.

15 changes: 4 additions & 11 deletions docs/storage/terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ The tables were created by [term_store.sql] which includes some documentation.
* [wbt_property_terms]
* [wbt_term_in_lang]
* [wbt_text_in_lang]
* [wbt_type]
* [wbt_text]

The relations are shown below:
Expand All @@ -35,7 +34,6 @@ digraph models_diagram{
wbt_term_in_lang -> wbt_item_terms [arrowhead="crow"]
wbt_term_in_lang -> wbt_property_terms [arrowhead="crow"]
wbt_text_in_lang -> wbt_term_in_lang [arrowhead="crow"]
wbt_type -> wbt_term_in_lang [arrowhead="crow"]
wbt_text -> wbt_text_in_lang [arrowhead="crow"]

}
Expand All @@ -55,12 +53,11 @@ The below query selects all terms in the tables for item Q123 and can be used as
```sql
SELECT
wbit_item_id as id,
wby_name as type,
wbtl_type_id as type_id,
wbxl_language as language,
wbx_text as text
FROM wbt_item_terms
LEFT JOIN wbt_term_in_lang ON wbit_term_in_lang_id = wbtl_id
LEFT JOIN wbt_type ON wbtl_type_id = wby_id
LEFT JOIN wbt_text_in_lang ON wbtl_text_in_lang_id = wbxl_id
LEFT JOIN wbt_text ON wbxl_text_id = wbx_id
WHERE wbit_item_id = 123;
Expand All @@ -71,12 +68,11 @@ For properties you can do something like:
```sql
SELECT
wbpt_property_id as id,
wby_name as type,
wbtl_type_id as type_id,
wbxl_language as language,
wbx_text as text
FROM wbt_property_terms
LEFT JOIN wbt_term_in_lang ON wbpt_term_in_lang_id = wbtl_id
LEFT JOIN wbt_type ON wbtl_type_id = wby_id
LEFT JOIN wbt_text_in_lang ON wbtl_text_in_lang_id = wbxl_id
LEFT JOIN wbt_text ON wbxl_text_id = wbx_id
WHERE wbpt_property_id = 10;
Expand All @@ -94,10 +90,9 @@ SELECT
wbx_text as text
FROM wbt_item_terms
LEFT JOIN wbt_term_in_lang ON wbit_term_in_lang_id = wbtl_id
LEFT JOIN wbt_type ON wbtl_type_id = wby_id
LEFT JOIN wbt_text_in_lang ON wbtl_text_in_lang_id = wbxl_id
LEFT JOIN wbt_text ON wbxl_text_id = wbx_id
WHERE wby_name = 'label'
WHERE wbtl_type_id = 1 -- label
AND wbxl_language = 'en'
AND wbx_text = 'Berlin';
```
Expand All @@ -112,10 +107,9 @@ SELECT
wbx_text as text
FROM wbt_property_terms
LEFT JOIN wbt_term_in_lang ON wbpt_term_in_lang_id = wbtl_id
LEFT JOIN wbt_type ON wbtl_type_id = wby_id
LEFT JOIN wbt_text_in_lang ON wbtl_text_in_lang_id = wbxl_id
LEFT JOIN wbt_text ON wbxl_text_id = wbx_id
WHERE wby_name = 'label'
WHERE wbtl_type_id = 1 -- label
AND wbxl_language = 'en'
AND wbx_text = 'instance of';
```
Expand All @@ -141,7 +135,6 @@ This is important for cases such as Wikidata that has publicly accessible databa
[wbt_term_in_lang]: @ref docs_sql_wbt_term_in_lang
[wbt_text_in_lang]: @ref docs_sql_wbt_text_in_lang
[wbt_text]: @ref docs_sql_wbt_text
[wbt_type]: @ref docs_sql_wbt_type
[ItemHandler::getSecondaryDataUpdates()]: @ref Wikibase::Repo::Content::ItemHandler::getSecondaryDataUpdates()
[PropertyHandler::getSecondaryDataUpdates()]: @ref Wikibase::Repo::Content::PropertyHandler::getSecondaryDataUpdates()
[EntityTermStoreWriter]: @ref Wikibase::Lib::Store::EntityTermStoreWriter
Expand Down
1 change: 0 additions & 1 deletion docs/topics/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @subpage docs_sql_wbt_property_terms
* @subpage docs_sql_wbt_term_in_lang
* @subpage docs_sql_wbt_text_in_lang
* @subpage docs_sql_wbt_type
* @subpage docs_sql_wbt_text

**Client**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function acquireTermInLangIds( array $termsArray, ?callable $callback = n

/**
* replace root keys containing type names in termsArray
* with their respective ids in wbt_type table
* with their respective ids in {@link TermTypeIds}
*
* @param array $termsArray terms per type per language:
* [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use MediaWikiIntegrationTestCase;
use Wikibase\Lib\Store\Sql\Terms\DatabaseInnerTermStoreCleaner;
use Wikibase\Lib\Store\Sql\Terms\TermTypeIds;
use Wikibase\Lib\WikibaseSettings;

/**
Expand All @@ -30,16 +31,12 @@ private function getCleaner(): DatabaseInnerTermStoreCleaner {
}

public function testCleanupEverything() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeId = $this->getDb()->insertId();

[ $text1Id, $text2Id ] = $this->insertTexts( [ 'a label', 'eine Bezeichnung' ] );
[ $textInLang1Id, $textInLang2Id ] = $this->insertTextsInLang( [ $text1Id => 'en', $text2Id => 'de' ] );
[ $termInLang1Id, $termInLang2Id ] = $this->insertTermsInLang( [ $textInLang1Id => $typeId, $textInLang2Id => $typeId ] );
[ $termInLang1Id, $termInLang2Id ] = $this->insertTermsInLang( [
$textInLang1Id => TermTypeIds::LABEL_TYPE_ID,
$textInLang2Id => TermTypeIds::LABEL_TYPE_ID,
] );

$this->getCleaner()->cleanTermInLangIds( $this->getDb(), $this->getDb(), [ $termInLang1Id, $termInLang2Id ] );

Expand All @@ -55,27 +52,9 @@ public function testCleanupEverything() {
->select( 'wbtl_id' )
->from( 'wbt_term_in_lang' )
->assertEmptyResult();
$this->newSelectQueryBuilder()
->select( 'wby_name' )
->from( 'wbt_type' )
->assertFieldValue( 'label' );
}

public function testCleanupTermInLangButNoTextInLang() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$type1Id = $this->getDb()->insertId();

$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'description' ] )
->caller( __METHOD__ )
->execute();
$type2Id = $this->getDb()->insertId();

// insert two texts into wbt_text
[ $text1Id, $text2Id ] = $this->insertTexts( [ 'some text', 'etwas Text' ] );

Expand All @@ -85,8 +64,8 @@ public function testCleanupTermInLangButNoTextInLang() {
// both texts are label & description in wbt_term_in_lang
[ $termInLang1Id, $termInLang2Id, $termInLang3Id, $termInLang4Id ] = $this->insertTermsInLang(
[
$textInLang1Id => [ $type1Id, $type2Id ],
$textInLang2Id => [ $type1Id, $type2Id ],
$textInLang1Id => [ TermTypeIds::LABEL_TYPE_ID, TermTypeIds::DESCRIPTION_TYPE_ID ],
$textInLang2Id => [ TermTypeIds::LABEL_TYPE_ID, TermTypeIds::DESCRIPTION_TYPE_ID ],
]
);

Expand All @@ -102,13 +81,6 @@ public function testCleanupTermInLangButNoTextInLang() {
}

public function testCleanupOneTextInLangButNoText() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeId = $this->getDb()->insertId();

// insert two texts into wbt_text
[ $text1Id, $text2Id ] = $this->insertTexts( [ 'text', 'Text' ] );

Expand All @@ -120,9 +92,9 @@ public function testCleanupOneTextInLangButNoText() {
// all terms are the same type
[ $termInLang1Id, $termInLang2Id, $termInLang3Id ] = $this->insertTermsInLang(
[
$textInLang1Id => $typeId,
$textInLang2Id => $typeId,
$textInLang3Id => $typeId,
$textInLang1Id => TermTypeIds::LABEL_TYPE_ID,
$textInLang2Id => TermTypeIds::LABEL_TYPE_ID,
$textInLang3Id => TermTypeIds::LABEL_TYPE_ID,
]
);

Expand All @@ -138,19 +110,15 @@ public function testCleanupOneTextInLangButNoText() {
}

public function testCleanupOneText() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeId = $this->getDb()->insertId();

// insert two texts into wbt_text
[ $text1Id, $text2Id ] = $this->insertTexts( [ 'text', 'Text' ] );

// insert into wbt_text_in_lang and term_in_lang
[ $textInLang1Id, $textInLang2Id ] = $this->insertTextsInLang( [ $text1Id => 'en', $text2Id => 'de' ] );
[ $termInLang1Id, $termInLang2Id ] = $this->insertTermsInLang( [ $textInLang1Id => $typeId, $textInLang2Id => $typeId ] );
[ $termInLang1Id, $termInLang2Id ] = $this->insertTermsInLang( [
$textInLang1Id => TermTypeIds::LABEL_TYPE_ID,
$textInLang2Id => TermTypeIds::LABEL_TYPE_ID,
] );

$this->getCleaner()->cleanTermInLangIds( $this->getDb(), $this->getDb(), [ $termInLang1Id ] );

Expand All @@ -161,16 +129,9 @@ public function testCleanupOneText() {
}

public function testCleanupLeavesUnrelatedTextsUntouched() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeId = $this->getDb()->insertId();

[ $text1Id, $text2Id ] = $this->insertTexts( [ 'a label', 'eine Bezeichnung' ] );
[ $textInLang1Id, $textInLang2Id ] = $this->insertTextsInLang( [ $text1Id => 'en', $text2Id => 'de' ] );
[ $termInLang1Id ] = $this->insertTermsInLang( [ $textInLang1Id => $typeId ] );
[ $termInLang1Id ] = $this->insertTermsInLang( [ $textInLang1Id => TermTypeIds::LABEL_TYPE_ID ] );

// remove the first
$this->getCleaner()->cleanTermInLangIds( $this->getDb(), $this->getDb(), [ $termInLang1Id ] );
Expand All @@ -183,20 +144,6 @@ public function testCleanupLeavesUnrelatedTextsUntouched() {
}

public function testT237984_sharedTextInLangIdsAreNotDeleted() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeIdLabel = $this->getDb()->insertId();

$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'description' ] )
->caller( __METHOD__ )
->execute();
$typeIdDescription = $this->getDb()->insertId();

[ $textId ] = $this->insertTexts( [ 'someText' ] );

[ $textInLangIdSingleUse1 ] = $this->insertTextsInLang( [ $textId => 'en' ] );
Expand All @@ -205,9 +152,9 @@ public function testT237984_sharedTextInLangIdsAreNotDeleted() {

[ $termInLangIdToDelete1, $termInLangIdToDelete2, $termInLangIdToDelete3, $termInLangIdToRemain ] = $this->insertTermsInLang(
[
$textInLangIdSingleUse1 => $typeIdLabel,
$textInLangIdSingleUse2 => $typeIdLabel,
$textInLangIdShared => [ $typeIdLabel, $typeIdDescription ],
$textInLangIdSingleUse1 => TermTypeIds::LABEL_TYPE_ID,
$textInLangIdSingleUse2 => TermTypeIds::LABEL_TYPE_ID,
$textInLangIdShared => [ TermTypeIds::LABEL_TYPE_ID, TermTypeIds::DESCRIPTION_TYPE_ID ],
]
);

Expand All @@ -224,13 +171,6 @@ public function testT237984_sharedTextInLangIdsAreNotDeleted() {
}

public function testT237984_sharedTextIdsAreNotDeleted() {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [ 'wby_name' => 'label' ] )
->caller( __METHOD__ )
->execute();
$typeIdLabel = $this->getDb()->insertId();

[ $textIdSingleUse, $textIdShared ] = $this->insertTexts( [ 'someText1', 'someText2' ] );

// insert a language for each, and one additional for the shared
Expand All @@ -244,9 +184,9 @@ public function testT237984_sharedTextIdsAreNotDeleted() {

[ $termInLangIdToDelete1, $termInLangIdToDelete2, $termInLangIdToRemain3 ] = $this->insertTermsInLang(
[
$textInLangIdToDelete1 => $typeIdLabel,
$textInLangIdToDelete2 => $typeIdLabel,
$textInLangIdToRemain3 => $typeIdLabel,
$textInLangIdToDelete1 => TermTypeIds::LABEL_TYPE_ID,
$textInLangIdToDelete2 => TermTypeIds::LABEL_TYPE_ID,
$textInLangIdToRemain3 => TermTypeIds::LABEL_TYPE_ID,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class TermInLangIdsResolverFactoryTest extends MediaWikiIntegrationTestCase {
'he' => 'שלום עולם',
];

private const MOCK_TYPE_LABEL = 1;
/**
* @var array
*/
Expand All @@ -45,15 +44,6 @@ private function setUpDB(): void {
$this->markTestSkipped( "Skipping because WikibaseClient doesn't have local term store tables." );
}

$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_type' )
->row( [
'wby_id' => self::MOCK_TYPE_LABEL,
'wby_name' => 'label',
] )
->caller( __METHOD__ )
->execute();

$fname = __METHOD__;
$this->termIds = array_map(
function ( string $lang, string $label ) use ( $fname ): int {
Expand All @@ -77,7 +67,7 @@ function ( string $lang, string $label ) use ( $fname ): int {
$this->getDb()->newInsertQueryBuilder()
->insertInto( 'wbt_term_in_lang' )
->row( [
'wbtl_type_id' => self::MOCK_TYPE_LABEL,
'wbtl_type_id' => TermTypeIds::LABEL_TYPE_ID,
'wbtl_text_in_lang_id' => $this->getDb()->insertId(),
] )
->caller( $fname )
Expand Down
Loading

0 comments on commit 00c1235

Please sign in to comment.