write and test the compat layer from v3 to v4

This commit is contained in:
Tamo 2022-10-09 02:49:42 +02:00 committed by Clément Renault
parent 089106a970
commit 22ffbf3676
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
17 changed files with 1791 additions and 39 deletions

View File

@ -13,6 +13,7 @@ use super::{
v6::{self, V6IndexReader, V6Reader},
};
pub mod v3_to_v4;
pub mod v4_to_v5;
pub mod v5_to_v6;

View File

@ -0,0 +1,5 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: documents
---
[]

View File

@ -0,0 +1,35 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: spells.settings()
---
Ok(
Settings {
displayed_attributes: Reset,
searchable_attributes: Reset,
filterable_attributes: Set(
{},
),
sortable_attributes: Set(
{},
),
ranking_rules: Set(
[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
],
),
stop_words: Set(
{},
),
synonyms: Set(
{},
),
distinct_attribute: Reset,
typo_tolerance: NotSet,
_kind: PhantomData<dump::reader::v4::settings::Checked>,
},
)

View File

@ -0,0 +1,533 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: documents
---
[
{
"index": "acid-arrow",
"name": "Acid Arrow",
"desc": [
"A shimmering green arrow streaks toward a target within range and bursts in a spray of acid. Make a ranged spell attack against the target. On a hit, the target takes 4d4 acid damage immediately and 2d4 acid damage at the end of its next turn. On a miss, the arrow splashes the target with acid for half as much of the initial damage and no damage at the end of its next turn."
],
"higher_level": [
"When you cast this spell using a spell slot of 3rd level or higher, the damage (both initial and later) increases by 1d4 for each slot level above 2nd."
],
"range": "90 feet",
"components": [
"V",
"S",
"M"
],
"material": "Powdered rhubarb leaf and an adder's stomach.",
"ritual": false,
"duration": "Instantaneous",
"concentration": false,
"casting_time": "1 action",
"level": 2,
"attack_type": "ranged",
"damage": {
"damage_type": {
"index": "acid",
"name": "Acid",
"url": "/api/damage-types/acid"
},
"damage_at_slot_level": {
"2": "4d4",
"3": "5d4",
"4": "6d4",
"5": "7d4",
"6": "8d4",
"7": "9d4",
"8": "10d4",
"9": "11d4"
}
},
"school": {
"index": "evocation",
"name": "Evocation",
"url": "/api/magic-schools/evocation"
},
"classes": [
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
},
{
"index": "land",
"name": "Land",
"url": "/api/subclasses/land"
}
],
"url": "/api/spells/acid-arrow"
},
{
"index": "acid-splash",
"name": "Acid Splash",
"desc": [
"You hurl a bubble of acid. Choose one creature within range, or choose two creatures within range that are within 5 feet of each other. A target must succeed on a dexterity saving throw or take 1d6 acid damage.",
"This spell's damage increases by 1d6 when you reach 5th level (2d6), 11th level (3d6), and 17th level (4d6)."
],
"range": "60 feet",
"components": [
"V",
"S"
],
"ritual": false,
"duration": "Instantaneous",
"concentration": false,
"casting_time": "1 action",
"level": 0,
"damage": {
"damage_type": {
"index": "acid",
"name": "Acid",
"url": "/api/damage-types/acid"
},
"damage_at_character_level": {
"1": "1d6",
"5": "2d6",
"11": "3d6",
"17": "4d6"
}
},
"school": {
"index": "conjuration",
"name": "Conjuration",
"url": "/api/magic-schools/conjuration"
},
"classes": [
{
"index": "sorcerer",
"name": "Sorcerer",
"url": "/api/classes/sorcerer"
},
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/acid-splash",
"dc": {
"dc_type": {
"index": "dex",
"name": "DEX",
"url": "/api/ability-scores/dex"
},
"dc_success": "none"
}
},
{
"index": "aid",
"name": "Aid",
"desc": [
"Your spell bolsters your allies with toughness and resolve. Choose up to three creatures within range. Each target's hit point maximum and current hit points increase by 5 for the duration."
],
"higher_level": [
"When you cast this spell using a spell slot of 3rd level or higher, a target's hit points increase by an additional 5 for each slot level above 2nd."
],
"range": "30 feet",
"components": [
"V",
"S",
"M"
],
"material": "A tiny strip of white cloth.",
"ritual": false,
"duration": "8 hours",
"concentration": false,
"casting_time": "1 action",
"level": 2,
"school": {
"index": "abjuration",
"name": "Abjuration",
"url": "/api/magic-schools/abjuration"
},
"classes": [
{
"index": "cleric",
"name": "Cleric",
"url": "/api/classes/cleric"
},
{
"index": "paladin",
"name": "Paladin",
"url": "/api/classes/paladin"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/aid",
"heal_at_slot_level": {
"2": "5",
"3": "10",
"4": "15",
"5": "20",
"6": "25",
"7": "30",
"8": "35",
"9": "40"
}
},
{
"index": "alarm",
"name": "Alarm",
"desc": [
"You set an alarm against unwanted intrusion. Choose a door, a window, or an area within range that is no larger than a 20-foot cube. Until the spell ends, an alarm alerts you whenever a Tiny or larger creature touches or enters the warded area. When you cast the spell, you can designate creatures that won't set off the alarm. You also choose whether the alarm is mental or audible.",
"A mental alarm alerts you with a ping in your mind if you are within 1 mile of the warded area. This ping awakens you if you are sleeping.",
"An audible alarm produces the sound of a hand bell for 10 seconds within 60 feet."
],
"range": "30 feet",
"components": [
"V",
"S",
"M"
],
"material": "A tiny bell and a piece of fine silver wire.",
"ritual": true,
"duration": "8 hours",
"concentration": false,
"casting_time": "1 minute",
"level": 1,
"school": {
"index": "abjuration",
"name": "Abjuration",
"url": "/api/magic-schools/abjuration"
},
"classes": [
{
"index": "ranger",
"name": "Ranger",
"url": "/api/classes/ranger"
},
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/alarm",
"area_of_effect": {
"type": "cube",
"size": 20
}
},
{
"index": "alter-self",
"name": "Alter Self",
"desc": [
"You assume a different form. When you cast the spell, choose one of the following options, the effects of which last for the duration of the spell. While the spell lasts, you can end one option as an action to gain the benefits of a different one.",
"***Aquatic Adaptation.*** You adapt your body to an aquatic environment, sprouting gills and growing webbing between your fingers. You can breathe underwater and gain a swimming speed equal to your walking speed.",
"***Change Appearance.*** You transform your appearance. You decide what you look like, including your height, weight, facial features, sound of your voice, hair length, coloration, and distinguishing characteristics, if any. You can make yourself appear as a member of another race, though none of your statistics change. You also can't appear as a creature of a different size than you, and your basic shape stays the same; if you're bipedal, you can't use this spell to become quadrupedal, for instance. At any time for the duration of the spell, you can use your action to change your appearance in this way again.",
"***Natural Weapons.*** You grow claws, fangs, spines, horns, or a different natural weapon of your choice. Your unarmed strikes deal 1d6 bludgeoning, piercing, or slashing damage, as appropriate to the natural weapon you chose, and you are proficient with your unarmed strikes. Finally, the natural weapon is magic and you have a +1 bonus to the attack and damage rolls you make using it."
],
"range": "Self",
"components": [
"V",
"S"
],
"ritual": false,
"duration": "Up to 1 hour",
"concentration": true,
"casting_time": "1 action",
"level": 2,
"school": {
"index": "transmutation",
"name": "Transmutation",
"url": "/api/magic-schools/transmutation"
},
"classes": [
{
"index": "sorcerer",
"name": "Sorcerer",
"url": "/api/classes/sorcerer"
},
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/alter-self"
},
{
"index": "animal-friendship",
"name": "Animal Friendship",
"desc": [
"This spell lets you convince a beast that you mean it no harm. Choose a beast that you can see within range. It must see and hear you. If the beast's Intelligence is 4 or higher, the spell fails. Otherwise, the beast must succeed on a wisdom saving throw or be charmed by you for the spell's duration. If you or one of your companions harms the target, the spells ends."
],
"range": "30 feet",
"components": [
"V",
"S",
"M"
],
"material": "A morsel of food.",
"ritual": false,
"duration": "24 hours",
"concentration": false,
"casting_time": "1 action",
"level": 1,
"school": {
"index": "enchantment",
"name": "Enchantment",
"url": "/api/magic-schools/enchantment"
},
"classes": [
{
"index": "bard",
"name": "Bard",
"url": "/api/classes/bard"
},
{
"index": "cleric",
"name": "Cleric",
"url": "/api/classes/cleric"
},
{
"index": "druid",
"name": "Druid",
"url": "/api/classes/druid"
},
{
"index": "ranger",
"name": "Ranger",
"url": "/api/classes/ranger"
}
],
"subclasses": [],
"url": "/api/spells/animal-friendship",
"dc": {
"dc_type": {
"index": "wis",
"name": "WIS",
"url": "/api/ability-scores/wis"
},
"dc_success": "none"
}
},
{
"index": "animal-messenger",
"name": "Animal Messenger",
"desc": [
"By means of this spell, you use an animal to deliver a message. Choose a Tiny beast you can see within range, such as a squirrel, a blue jay, or a bat. You specify a location, which you must have visited, and a recipient who matches a general description, such as \"a man or woman dressed in the uniform of the town guard\" or \"a red-haired dwarf wearing a pointed hat.\" You also speak a message of up to twenty-five words. The target beast travels for the duration of the spell toward the specified location, covering about 50 miles per 24 hours for a flying messenger, or 25 miles for other animals.",
"When the messenger arrives, it delivers your message to the creature that you described, replicating the sound of your voice. The messenger speaks only to a creature matching the description you gave. If the messenger doesn't reach its destination before the spell ends, the message is lost, and the beast makes its way back to where you cast this spell."
],
"higher_level": [
"If you cast this spell using a spell slot of 3nd level or higher, the duration of the spell increases by 48 hours for each slot level above 2nd."
],
"range": "30 feet",
"components": [
"V",
"S",
"M"
],
"material": "A morsel of food.",
"ritual": true,
"duration": "24 hours",
"concentration": false,
"casting_time": "1 action",
"level": 2,
"school": {
"index": "enchantment",
"name": "Enchantment",
"url": "/api/magic-schools/enchantment"
},
"classes": [
{
"index": "bard",
"name": "Bard",
"url": "/api/classes/bard"
},
{
"index": "druid",
"name": "Druid",
"url": "/api/classes/druid"
},
{
"index": "ranger",
"name": "Ranger",
"url": "/api/classes/ranger"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/animal-messenger"
},
{
"index": "animal-shapes",
"name": "Animal Shapes",
"desc": [
"Your magic turns others into beasts. Choose any number of willing creatures that you can see within range. You transform each target into the form of a Large or smaller beast with a challenge rating of 4 or lower. On subsequent turns, you can use your action to transform affected creatures into new forms.",
"The transformation lasts for the duration for each target, or until the target drops to 0 hit points or dies. You can choose a different form for each target. A target's game statistics are replaced by the statistics of the chosen beast, though the target retains its alignment and Intelligence, Wisdom, and Charisma scores. The target assumes the hit points of its new form, and when it reverts to its normal form, it returns to the number of hit points it had before it transformed. If it reverts as a result of dropping to 0 hit points, any excess damage carries over to its normal form. As long as the excess damage doesn't reduce the creature's normal form to 0 hit points, it isn't knocked unconscious. The creature is limited in the actions it can perform by the nature of its new form, and it can't speak or cast spells.",
"The target's gear melds into the new form. The target can't activate, wield, or otherwise benefit from any of its equipment."
],
"range": "30 feet",
"components": [
"V",
"S"
],
"ritual": false,
"duration": "Up to 24 hours",
"concentration": true,
"casting_time": "1 action",
"level": 8,
"school": {
"index": "transmutation",
"name": "Transmutation",
"url": "/api/magic-schools/transmutation"
},
"classes": [
{
"index": "druid",
"name": "Druid",
"url": "/api/classes/druid"
}
],
"subclasses": [],
"url": "/api/spells/animal-shapes"
},
{
"index": "animate-dead",
"name": "Animate Dead",
"desc": [
"This spell creates an undead servant. Choose a pile of bones or a corpse of a Medium or Small humanoid within range. Your spell imbues the target with a foul mimicry of life, raising it as an undead creature. The target becomes a skeleton if you chose bones or a zombie if you chose a corpse (the DM has the creature's game statistics).",
"On each of your turns, you can use a bonus action to mentally command any creature you made with this spell if the creature is within 60 feet of you (if you control multiple creatures, you can command any or all of them at the same time, issuing the same command to each one). You decide what action the creature will take and where it will move during its next turn, or you can issue a general command, such as to guard a particular chamber or corridor. If you issue no commands, the creature only defends itself against hostile creatures. Once given an order, the creature continues to follow it until its task is complete.",
"The creature is under your control for 24 hours, after which it stops obeying any command you've given it. To maintain control of the creature for another 24 hours, you must cast this spell on the creature again before the current 24-hour period ends. This use of the spell reasserts your control over up to four creatures you have animated with this spell, rather than animating a new one."
],
"higher_level": [
"When you cast this spell using a spell slot of 4th level or higher, you animate or reassert control over two additional undead creatures for each slot level above 3rd. Each of the creatures must come from a different corpse or pile of bones."
],
"range": "10 feet",
"components": [
"V",
"S",
"M"
],
"material": "A drop of blood, a piece of flesh, and a pinch of bone dust.",
"ritual": false,
"duration": "Instantaneous",
"concentration": false,
"casting_time": "1 minute",
"level": 3,
"school": {
"index": "necromancy",
"name": "Necromancy",
"url": "/api/magic-schools/necromancy"
},
"classes": [
{
"index": "cleric",
"name": "Cleric",
"url": "/api/classes/cleric"
},
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [
{
"index": "lore",
"name": "Lore",
"url": "/api/subclasses/lore"
}
],
"url": "/api/spells/animate-dead"
},
{
"index": "animate-objects",
"name": "Animate Objects",
"desc": [
"Objects come to life at your command. Choose up to ten nonmagical objects within range that are not being worn or carried. Medium targets count as two objects, Large targets count as four objects, Huge targets count as eight objects. You can't animate any object larger than Huge. Each target animates and becomes a creature under your control until the spell ends or until reduced to 0 hit points.",
"As a bonus action, you can mentally command any creature you made with this spell if the creature is within 500 feet of you (if you control multiple creatures, you can command any or all of them at the same time, issuing the same command to each one). You decide what action the creature will take and where it will move during its next turn, or you can issue a general command, such as to guard a particular chamber or corridor. If you issue no commands, the creature only defends itself against hostile creatures. Once given an order, the creature continues to follow it until its task is complete.",
"##### Animated Object Statistics",
"| Size | HP | AC | Attack | Str | Dex |",
"|---|---|---|---|---|---|",
"| Tiny | 20 | 18 | +8 to hit, 1d4 + 4 damage | 4 | 18 |",
"| Small | 25 | 16 | +6 to hit, 1d8 + 2 damage | 6 | 14 |",
"| Medium | 40 | 13 | +5 to hit, 2d6 + 1 damage | 10 | 12 |",
"| Large | 50 | 10 | +6 to hit, 2d10 + 2 damage | 14 | 10 |",
"| Huge | 80 | 10 | +8 to hit, 2d12 + 4 damage | 18 | 6 |",
"An animated object is a construct with AC, hit points, attacks, Strength, and Dexterity determined by its size. Its Constitution is 10 and its Intelligence and Wisdom are 3, and its Charisma is 1. Its speed is 30 feet; if the object lacks legs or other appendages it can use for locomotion, it instead has a flying speed of 30 feet and can hover. If the object is securely attached to a surface or a larger object, such as a chain bolted to a wall, its speed is 0. It has blindsight with a radius of 30 feet and is blind beyond that distance. When the animated object drops to 0 hit points, it reverts to its original object form, and any remaining damage carries over to its original object form.",
"If you command an object to attack, it can make a single melee attack against a creature within 5 feet of it. It makes a slam attack with an attack bonus and bludgeoning damage determined by its size. The DM might rule that a specific object inflicts slashing or piercing damage based on its form."
],
"higher_level": [
"If you cast this spell using a spell slot of 6th level or higher, you can animate two additional objects for each slot level above 5th."
],
"range": "120 feet",
"components": [
"V",
"S"
],
"ritual": false,
"duration": "Up to 1 minute",
"concentration": true,
"casting_time": "1 action",
"level": 5,
"school": {
"index": "transmutation",
"name": "Transmutation",
"url": "/api/magic-schools/transmutation"
},
"classes": [
{
"index": "bard",
"name": "Bard",
"url": "/api/classes/bard"
},
{
"index": "sorcerer",
"name": "Sorcerer",
"url": "/api/classes/sorcerer"
},
{
"index": "wizard",
"name": "Wizard",
"url": "/api/classes/wizard"
}
],
"subclasses": [],
"url": "/api/spells/animate-objects"
}
]

View File

@ -0,0 +1,321 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: tasks
---
[
{
"id": 0,
"index_uid": "movies_2",
"content": {
"DocumentAddition": {
"content_uuid": "66d3f12d-fcf3-4b53-88cb-407017373de7",
"merge_strategy": "ReplaceDocuments",
"primary_key": null,
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:39:03.703667164Z"
}
]
},
{
"id": 0,
"index_uid": "movies",
"content": {
"DocumentAddition": {
"content_uuid": "378e1055-84e1-40e6-9328-176b1781850e",
"merge_strategy": "ReplaceDocuments",
"primary_key": null,
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:54.004402239Z"
},
{
"Processing": "2022-10-07T11:38:54.011081233Z"
},
{
"Succeded": {
"result": {
"DocumentAddition": {
"indexed_documents": 10
}
},
"timestamp": "2022-10-07T11:38:54.026649575Z"
}
}
]
},
{
"id": 1,
"index_uid": "movies",
"content": {
"SettingsUpdate": {
"settings": {
"filterableAttributes": [
"genres",
"id"
],
"sortableAttributes": [
"release_date"
]
},
"is_deletion": false,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:54.217852146Z"
},
{
"Processing": "2022-10-07T11:38:54.23264073Z"
},
{
"Succeded": {
"result": "Other",
"timestamp": "2022-10-07T11:38:54.245649334Z"
}
}
]
},
{
"id": 2,
"index_uid": "movies",
"content": {
"SettingsUpdate": {
"settings": {
"rankingRules": [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc"
]
},
"is_deletion": false,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:54.438833927Z"
},
{
"Processing": "2022-10-07T11:38:54.453596791Z"
},
{
"Succeded": {
"result": "Other",
"timestamp": "2022-10-07T11:38:54.456346121Z"
}
}
]
},
{
"id": 3,
"index_uid": "movies",
"content": {
"DocumentAddition": {
"content_uuid": "48997745-7615-4349-9a50-4324cc3745c0",
"merge_strategy": "ReplaceDocuments",
"primary_key": null,
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:39:03.695252071Z"
},
{
"Processing": "2022-10-07T11:39:03.698139272Z"
},
{
"Succeded": {
"result": {
"DocumentAddition": {
"indexed_documents": 100
}
},
"timestamp": "2022-10-07T11:39:04.188852537Z"
}
}
]
},
{
"id": 0,
"index_uid": "products",
"content": {
"SettingsUpdate": {
"settings": {
"synonyms": {
"android": [
"phone",
"smartphone"
],
"iphone": [
"phone",
"smartphone"
],
"phone": [
"smartphone",
"iphone",
"android"
]
}
},
"is_deletion": false,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:54.734594617Z"
},
{
"Processing": "2022-10-07T11:38:54.737274016Z"
},
{
"Succeded": {
"result": "Other",
"timestamp": "2022-10-07T11:38:54.74389899Z"
}
}
]
},
{
"id": 1,
"index_uid": "products",
"content": {
"DocumentAddition": {
"content_uuid": "94b720e4-d6ad-49e1-ba02-34773eecab2a",
"merge_strategy": "ReplaceDocuments",
"primary_key": null,
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:55.350510177Z"
},
{
"Processing": "2022-10-07T11:38:55.353402439Z"
},
{
"Failed": {
"error": {
"message": "The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index.",
"code": "primary_key_inference_failed",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#primary_key_inference_failed"
},
"timestamp": "2022-10-07T11:38:55.35349514Z"
}
}
]
},
{
"id": 2,
"index_uid": "products",
"content": {
"DocumentAddition": {
"content_uuid": "0b65a2d5-04e2-4529-b123-df01831ca2c0",
"merge_strategy": "ReplaceDocuments",
"primary_key": "sku",
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:55.940610428Z"
},
{
"Processing": "2022-10-07T11:38:55.951485379Z"
},
{
"Succeded": {
"result": {
"DocumentAddition": {
"indexed_documents": 10
}
},
"timestamp": "2022-10-07T11:38:55.963185778Z"
}
}
]
},
{
"id": 0,
"index_uid": "dnd_spells",
"content": {
"DocumentAddition": {
"content_uuid": "d95dc3d2-30be-40d1-b3b3-057083499f71",
"merge_strategy": "ReplaceDocuments",
"primary_key": null,
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:56.263041061Z"
},
{
"Processing": "2022-10-07T11:38:56.265837882Z"
},
{
"Failed": {
"error": {
"message": "The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index.",
"code": "primary_key_inference_failed",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#primary_key_inference_failed"
},
"timestamp": "2022-10-07T11:38:56.265951133Z"
}
}
]
},
{
"id": 1,
"index_uid": "dnd_spells",
"content": {
"DocumentAddition": {
"content_uuid": "39aa01c5-c4e1-42af-8063-b6f6afbf5b98",
"merge_strategy": "ReplaceDocuments",
"primary_key": "index",
"documents_count": 0,
"allow_index_creation": true
}
},
"events": [
{
"Created": "2022-10-07T11:38:56.501949087Z"
},
{
"Processing": "2022-10-07T11:38:56.504677498Z"
},
{
"Succeded": {
"result": {
"DocumentAddition": {
"indexed_documents": 10
}
},
"timestamp": "2022-10-07T11:38:56.521004328Z"
}
}
]
}
]

View File

@ -0,0 +1,5 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: keys
---
[]

View File

@ -0,0 +1,49 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: products.settings()
---
Ok(
Settings {
displayed_attributes: Reset,
searchable_attributes: Reset,
filterable_attributes: Set(
{},
),
sortable_attributes: Set(
{},
),
ranking_rules: Set(
[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
],
),
stop_words: Set(
{},
),
synonyms: Set(
{
"android": [
"phone",
"smartphone",
],
"iphone": [
"phone",
"smartphone",
],
"phone": [
"android",
"iphone",
"smartphone",
],
},
),
distinct_attribute: Reset,
typo_tolerance: NotSet,
_kind: PhantomData<dump::reader::v4::settings::Checked>,
},
)

View File

@ -0,0 +1,308 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: documents
---
[
{
"sku": 127687,
"name": "Duracell - AA Batteries (8-Pack)",
"type": "HardGood",
"price": 7.49,
"upc": "041333825014",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "Compatible with select electronic devices; AA size; DURALOCK Power Preserve technology; 8-pack",
"manufacturer": "Duracell",
"model": "MN1500B8Z",
"url": "http://www.bestbuy.com/site/duracell-aa-batteries-8-pack/127687.p?id=1051384045676&skuId=127687&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/1276/127687_sa.jpg"
},
{
"sku": 150115,
"name": "Energizer - MAX Batteries AA (4-Pack)",
"type": "HardGood",
"price": 4.99,
"upc": "039800011329",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "4-pack AA alkaline batteries; battery tester included",
"manufacturer": "Energizer",
"model": "E91BP-4",
"url": "http://www.bestbuy.com/site/energizer-max-batteries-aa-4-pack/150115.p?id=1051384046217&skuId=150115&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/1501/150115_sa.jpg"
},
{
"sku": 185230,
"name": "Duracell - C Batteries (4-Pack)",
"type": "HardGood",
"price": 8.99,
"upc": "041333440019",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "Compatible with select electronic devices; C size; DURALOCK Power Preserve technology; 4-pack",
"manufacturer": "Duracell",
"model": "MN1400R4Z",
"url": "http://www.bestbuy.com/site/duracell-c-batteries-4-pack/185230.p?id=1051384046486&skuId=185230&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/1852/185230_sa.jpg"
},
{
"sku": 185267,
"name": "Duracell - D Batteries (4-Pack)",
"type": "HardGood",
"price": 9.99,
"upc": "041333430010",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.99,
"description": "Compatible with select electronic devices; D size; DURALOCK Power Preserve technology; 4-pack",
"manufacturer": "Duracell",
"model": "MN1300R4Z",
"url": "http://www.bestbuy.com/site/duracell-d-batteries-4-pack/185267.p?id=1051384046551&skuId=185267&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/1852/185267_sa.jpg"
},
{
"sku": 312290,
"name": "Duracell - 9V Batteries (2-Pack)",
"type": "HardGood",
"price": 7.99,
"upc": "041333216010",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "Compatible with select electronic devices; alkaline chemistry; 9V size; DURALOCK Power Preserve technology; 2-pack",
"manufacturer": "Duracell",
"model": "MN1604B2Z",
"url": "http://www.bestbuy.com/site/duracell-9v-batteries-2-pack/312290.p?id=1051384050321&skuId=312290&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/3122/312290_sa.jpg"
},
{
"sku": 324884,
"name": "Directed Electronics - Viper Audio Glass Break Sensor",
"type": "HardGood",
"price": 39.99,
"upc": "093207005060",
"category": [
{
"id": "pcmcat113100050015",
"name": "Carfi Instore Only"
}
],
"shipping": 0,
"description": "From our expanded online assortment; compatible with Directed Electronics alarm systems; microphone and microprocessor detect and analyze intrusions; detects quiet glass breaks",
"manufacturer": "Directed Electronics",
"model": "506T",
"url": "http://www.bestbuy.com/site/directed-electronics-viper-audio-glass-break-sensor/324884.p?id=1112808077651&skuId=324884&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/3248/324884_rc.jpg"
},
{
"sku": 333179,
"name": "Energizer - N Cell E90 Batteries (2-Pack)",
"type": "HardGood",
"price": 5.99,
"upc": "039800013200",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208006",
"name": "Specialty Batteries"
}
],
"shipping": 5.49,
"description": "Alkaline batteries; 1.5V",
"manufacturer": "Energizer",
"model": "E90BP-2",
"url": "http://www.bestbuy.com/site/energizer-n-cell-e90-batteries-2-pack/333179.p?id=1185268509951&skuId=333179&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/3331/333179_sa.jpg"
},
{
"sku": 346575,
"name": "Metra - Radio Installation Dash Kit for Most 1989-2000 Ford, Lincoln & Mercury Vehicles - Black",
"type": "HardGood",
"price": 16.99,
"upc": "086429002757",
"category": [
{
"id": "abcat0300000",
"name": "Car Electronics & GPS"
},
{
"id": "pcmcat165900050023",
"name": "Car Installation Parts & Accessories"
},
{
"id": "pcmcat331600050007",
"name": "Car Audio Installation Parts"
},
{
"id": "pcmcat165900050031",
"name": "Deck Installation Parts"
},
{
"id": "pcmcat165900050033",
"name": "Dash Installation Kits"
}
],
"shipping": 0,
"description": "From our expanded online assortment; compatible with most 1989-2000 Ford, Lincoln and Mercury vehicles; snap-in TurboKit offers fast installation; spacer/trim ring; rear support bracket",
"manufacturer": "Metra",
"model": "99-5512",
"url": "http://www.bestbuy.com/site/metra-radio-installation-dash-kit-for-most-1989-2000-ford-lincoln-mercury-vehicles-black/346575.p?id=1218118704590&skuId=346575&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/3465/346575_rc.jpg"
},
{
"sku": 43900,
"name": "Duracell - AAA Batteries (4-Pack)",
"type": "HardGood",
"price": 5.49,
"upc": "041333424019",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "Compatible with select electronic devices; AAA size; DURALOCK Power Preserve technology; 4-pack",
"manufacturer": "Duracell",
"model": "MN2400B4Z",
"url": "http://www.bestbuy.com/site/duracell-aaa-batteries-4-pack/43900.p?id=1051384074145&skuId=43900&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/4390/43900_sa.jpg"
},
{
"sku": 48530,
"name": "Duracell - AA 1.5V CopperTop Batteries (4-Pack)",
"type": "HardGood",
"price": 5.49,
"upc": "041333415017",
"category": [
{
"id": "pcmcat312300050015",
"name": "Connected Home & Housewares"
},
{
"id": "pcmcat248700050021",
"name": "Housewares"
},
{
"id": "pcmcat303600050001",
"name": "Household Batteries"
},
{
"id": "abcat0208002",
"name": "Alkaline Batteries"
}
],
"shipping": 5.49,
"description": "Long-lasting energy; DURALOCK Power Preserve technology; for toys, clocks, radios, games, remotes, PDAs and more",
"manufacturer": "Duracell",
"model": "MN1500B4Z",
"url": "http://www.bestbuy.com/site/duracell-aa-1-5v-coppertop-batteries-4-pack/48530.p?id=1099385268988&skuId=48530&cmp=RMXCC",
"image": "http://img.bbystatic.com/BestBuy_US/images/products/4853/48530_sa.jpg"
}
]

View File

@ -0,0 +1,35 @@
---
source: dump/src/reader/compat/v3_to_v4.rs
expression: movies2.settings()
---
Ok(
Settings {
displayed_attributes: Reset,
searchable_attributes: Reset,
filterable_attributes: Set(
{},
),
sortable_attributes: Set(
{},
),
ranking_rules: Set(
[
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
],
),
stop_words: Set(
{},
),
synonyms: Set(
{},
),
distinct_attribute: Reset,
typo_tolerance: NotSet,
_kind: PhantomData<dump::reader::v4::settings::Checked>,
},
)

View File

@ -0,0 +1,401 @@
use std::fs::File;
use uuid::Uuid;
use crate::reader::{v3, v4, DumpReader, IndexReader};
use crate::Result;
use super::v4_to_v5::CompatV4ToV5;
pub struct CompatV3ToV4 {
pub from: v3::V3Reader,
}
impl CompatV3ToV4 {
pub fn new(v3: v3::V3Reader) -> CompatV3ToV4 {
CompatV3ToV4 { from: v3 }
}
pub fn to_v5(self) -> CompatV4ToV5 {
CompatV4ToV5::Compat(self)
}
pub fn version(&self) -> crate::Version {
self.from.version()
}
pub fn date(&self) -> Option<time::OffsetDateTime> {
self.from.date()
}
pub fn instance_uid(&self) -> Result<Option<uuid::Uuid>> {
Ok(None)
}
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<CompatIndexV3ToV4>> + '_> {
Ok(self.from.indexes()?.map(|index_reader| -> Result<_> {
let compat = CompatIndexV3ToV4::new(index_reader?);
Ok(compat)
}))
}
pub fn tasks(
&mut self,
) -> Box<dyn Iterator<Item = Result<(v4::Task, Option<v4::UpdateFile>)>> + '_> {
let indexes = self.from.index_uuid.clone();
Box::new(
self.from
.tasks()
.map(move |task| {
task.map(|(task, content_file)| {
let index_uid = indexes
.iter()
.find(|index| index.uuid == task.uuid)
.map(|index| index.uid.clone());
let index_uid = match index_uid {
Some(uid) => uid.to_string(),
None => {
log::warn!(
"Error while importing the update {}.",
task.update.id()
);
log::warn!(
"The index associated to the uuid `{}` could not be retrieved.",
task.uuid.to_string()
);
if task.update.is_finished() {
// we're fucking with his history but not his data, that's ok-ish.
log::warn!("The index-uuid will be set as `unknown`.");
String::from("unknown")
} else {
log::warn!("The task will be ignored.");
return None;
}
}
};
let task = v4::Task {
id: task.update.id() as u32,
index_uid: v4::meta::IndexUid(index_uid),
content: match task.update.meta() {
v3::Kind::DeleteDocuments(documents) => {
v4::tasks::TaskContent::DocumentDeletion(
v4::tasks::DocumentDeletion::Ids(documents.clone()),
)
}
v3::Kind::DocumentAddition {
primary_key,
method,
content_uuid,
} => v4::tasks::TaskContent::DocumentAddition {
merge_strategy: match method {
v3::updates::IndexDocumentsMethod::ReplaceDocuments => {
v4::tasks::IndexDocumentsMethod::ReplaceDocuments
}
v3::updates::IndexDocumentsMethod::UpdateDocuments => {
v4::tasks::IndexDocumentsMethod::UpdateDocuments
}
},
primary_key: primary_key.clone(),
documents_count: 0, // we don't have this info
allow_index_creation: true, // there was no API-key in the v3
content_uuid: content_uuid.clone(),
},
v3::Kind::Settings(settings) => {
v4::tasks::TaskContent::SettingsUpdate {
settings: v4::Settings::from(settings.clone()),
is_deletion: false, // that didn't exist at this time
allow_index_creation: true, // there was no API-key in the v3
}
}
v3::Kind::ClearDocuments => {
v4::tasks::TaskContent::DocumentDeletion(
v4::tasks::DocumentDeletion::Clear,
)
}
},
events: match task.update {
v3::Status::Processing(processing) => {
vec![v4::tasks::TaskEvent::Created(processing.from.enqueued_at)]
}
v3::Status::Enqueued(enqueued) => {
vec![v4::tasks::TaskEvent::Created(enqueued.enqueued_at)]
}
v3::Status::Processed(processed) => {
vec![
v4::tasks::TaskEvent::Created(
processed.from.from.enqueued_at,
),
v4::tasks::TaskEvent::Processing(
processed.from.started_processing_at,
),
v4::tasks::TaskEvent::Succeded {
result: match processed.success {
v3::updates::UpdateResult::DocumentsAddition(
document_addition,
) => v4::tasks::TaskResult::DocumentAddition {
indexed_documents: document_addition
.nb_documents
as u64,
},
v3::updates::UpdateResult::DocumentDeletion {
deleted,
} => v4::tasks::TaskResult::DocumentDeletion {
deleted_documents: deleted,
},
v3::updates::UpdateResult::Other => {
v4::tasks::TaskResult::Other
}
},
timestamp: processed.processed_at,
},
]
}
v3::Status::Failed(failed) => vec![
v4::tasks::TaskEvent::Created(failed.from.from.enqueued_at),
v4::tasks::TaskEvent::Processing(
failed.from.started_processing_at,
),
v4::tasks::TaskEvent::Failed {
error: v4::ResponseError::from_msg(
failed.msg.to_string(),
failed.code.into(),
),
timestamp: failed.failed_at,
},
],
v3::Status::Aborted(aborted) => vec![
v4::tasks::TaskEvent::Created(aborted.from.enqueued_at),
v4::tasks::TaskEvent::Failed {
error: v4::ResponseError::from_msg(
"Task was aborted in a previous version of meilisearch."
.to_string(),
v4::errors::Code::UnretrievableErrorCode,
),
timestamp: aborted.aborted_at,
},
],
},
};
Some((task, content_file))
})
})
.filter_map(|res| res.transpose()),
)
}
pub fn keys(&mut self) -> Box<dyn Iterator<Item = Result<v4::Key>> + '_> {
Box::new(std::iter::empty())
}
}
pub struct CompatIndexV3ToV4 {
from: v3::V3IndexReader,
}
impl CompatIndexV3ToV4 {
pub fn new(v3: v3::V3IndexReader) -> CompatIndexV3ToV4 {
CompatIndexV3ToV4 { from: v3 }
}
pub fn metadata(&self) -> &crate::IndexMetadata {
self.from.metadata()
}
pub fn documents(&mut self) -> Result<Box<dyn Iterator<Item = Result<v4::Document>> + '_>> {
self.from
.documents()
.map(|iter| Box::new(iter) as Box<dyn Iterator<Item = Result<v4::Document>> + '_>)
}
pub fn settings(&mut self) -> Result<v4::Settings<v4::Checked>> {
Ok(v4::Settings::<v4::Unchecked>::from(self.from.settings()?).check())
}
}
impl<T> From<v3::Setting<T>> for v4::Setting<T> {
fn from(setting: v3::Setting<T>) -> Self {
match setting {
v3::Setting::Set(t) => v4::Setting::Set(t),
v3::Setting::Reset => v4::Setting::Reset,
v3::Setting::NotSet => v4::Setting::NotSet,
}
}
}
impl From<v3::Code> for v4::Code {
fn from(code: v3::Code) -> Self {
match code {
v3::Code::CreateIndex => v4::Code::CreateIndex,
v3::Code::IndexAlreadyExists => v4::Code::IndexAlreadyExists,
v3::Code::IndexNotFound => v4::Code::IndexNotFound,
v3::Code::InvalidIndexUid => v4::Code::InvalidIndexUid,
v3::Code::InvalidState => v4::Code::InvalidState,
v3::Code::MissingPrimaryKey => v4::Code::MissingPrimaryKey,
v3::Code::PrimaryKeyAlreadyPresent => v4::Code::PrimaryKeyAlreadyPresent,
v3::Code::MaxFieldsLimitExceeded => v4::Code::MaxFieldsLimitExceeded,
v3::Code::MissingDocumentId => v4::Code::MissingDocumentId,
v3::Code::InvalidDocumentId => v4::Code::InvalidDocumentId,
v3::Code::Filter => v4::Code::Filter,
v3::Code::Sort => v4::Code::Sort,
v3::Code::BadParameter => v4::Code::BadParameter,
v3::Code::BadRequest => v4::Code::BadRequest,
v3::Code::DatabaseSizeLimitReached => v4::Code::DatabaseSizeLimitReached,
v3::Code::DocumentNotFound => v4::Code::DocumentNotFound,
v3::Code::Internal => v4::Code::Internal,
v3::Code::InvalidGeoField => v4::Code::InvalidGeoField,
v3::Code::InvalidRankingRule => v4::Code::InvalidRankingRule,
v3::Code::InvalidStore => v4::Code::InvalidStore,
v3::Code::InvalidToken => v4::Code::InvalidToken,
v3::Code::MissingAuthorizationHeader => v4::Code::MissingAuthorizationHeader,
v3::Code::NoSpaceLeftOnDevice => v4::Code::NoSpaceLeftOnDevice,
v3::Code::DumpNotFound => v4::Code::DumpNotFound,
v3::Code::TaskNotFound => v4::Code::TaskNotFound,
v3::Code::PayloadTooLarge => v4::Code::PayloadTooLarge,
v3::Code::RetrieveDocument => v4::Code::RetrieveDocument,
v3::Code::SearchDocuments => v4::Code::SearchDocuments,
v3::Code::UnsupportedMediaType => v4::Code::UnsupportedMediaType,
v3::Code::DumpAlreadyInProgress => v4::Code::DumpAlreadyInProgress,
v3::Code::DumpProcessFailed => v4::Code::DumpProcessFailed,
v3::Code::InvalidContentType => v4::Code::InvalidContentType,
v3::Code::MissingContentType => v4::Code::MissingContentType,
v3::Code::MalformedPayload => v4::Code::MalformedPayload,
v3::Code::MissingPayload => v4::Code::MissingPayload,
}
}
}
impl<T> From<v3::Settings<T>> for v4::Settings<v4::Unchecked> {
fn from(settings: v3::Settings<T>) -> Self {
v4::Settings {
displayed_attributes: settings.displayed_attributes.into(),
searchable_attributes: settings.searchable_attributes.into(),
filterable_attributes: settings.filterable_attributes.into(),
sortable_attributes: settings.sortable_attributes.into(),
ranking_rules: settings.ranking_rules.into(),
stop_words: settings.stop_words.into(),
synonyms: settings.synonyms.into(),
distinct_attribute: settings.distinct_attribute.into(),
typo_tolerance: v4::Setting::NotSet,
_kind: std::marker::PhantomData,
}
}
}
#[cfg(test)]
pub(crate) mod test {
use std::{fs::File, io::BufReader};
use flate2::bufread::GzDecoder;
use tempfile::TempDir;
use super::*;
#[test]
fn compat_v3_v4() {
let dump = File::open("tests/assets/v3.dump").unwrap();
let dir = TempDir::new().unwrap();
let mut dump = BufReader::new(dump);
let gz = GzDecoder::new(&mut dump);
let mut archive = tar::Archive::new(gz);
archive.unpack(dir.path()).unwrap();
let mut dump = v3::V3Reader::open(dir).unwrap().to_v4();
// top level infos
insta::assert_display_snapshot!(dump.date().unwrap(), @"2022-10-07 11:39:03.709153554 +00:00:00");
// tasks
let tasks = dump.tasks().collect::<Result<Vec<_>>>().unwrap();
let (tasks, update_files): (Vec<_>, Vec<_>) = tasks.into_iter().unzip();
insta::assert_json_snapshot!(tasks);
assert_eq!(update_files.len(), 10);
assert!(update_files[0].is_some()); // the enqueued document addition
assert!(update_files[1..].iter().all(|u| u.is_none())); // everything already processed
// keys
let keys = dump.keys().collect::<Result<Vec<_>>>().unwrap();
insta::assert_json_snapshot!(keys, { "[].uid" => "[uuid]" });
// indexes
let mut indexes = dump.indexes().unwrap().collect::<Result<Vec<_>>>().unwrap();
// the index are not ordered in any way by default
indexes.sort_by_key(|index| index.metadata().uid.to_string());
let mut products = indexes.pop().unwrap();
let mut movies2 = indexes.pop().unwrap();
let mut movies = indexes.pop().unwrap();
let mut spells = indexes.pop().unwrap();
assert!(indexes.is_empty());
// products
insta::assert_json_snapshot!(products.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
{
"uid": "products",
"primaryKey": "sku",
"createdAt": "[now]",
"updatedAt": "[now]"
}
"###);
insta::assert_debug_snapshot!(products.settings());
let documents = products
.documents()
.unwrap()
.collect::<Result<Vec<_>>>()
.unwrap();
assert_eq!(documents.len(), 10);
insta::assert_json_snapshot!(documents);
// movies
insta::assert_json_snapshot!(movies.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
{
"uid": "movies",
"primaryKey": "id",
"createdAt": "[now]",
"updatedAt": "[now]"
}
"###);
// movies2
insta::assert_json_snapshot!(movies2.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
{
"uid": "movies_2",
"primaryKey": null,
"createdAt": "[now]",
"updatedAt": "[now]"
}
"###);
insta::assert_debug_snapshot!(movies2.settings());
let documents = movies2
.documents()
.unwrap()
.collect::<Result<Vec<_>>>()
.unwrap();
assert_eq!(documents.len(), 0);
insta::assert_debug_snapshot!(documents);
// spells
insta::assert_json_snapshot!(spells.metadata(), { ".createdAt" => "[now]", ".updatedAt" => "[now]" }, @r###"
{
"uid": "dnd_spells",
"primaryKey": "index",
"createdAt": "[now]",
"updatedAt": "[now]"
}
"###);
insta::assert_debug_snapshot!(spells.settings());
let documents = spells
.documents()
.unwrap()
.collect::<Result<Vec<_>>>()
.unwrap();
assert_eq!(documents.len(), 10);
insta::assert_json_snapshot!(documents);
}
}

View File

@ -3,15 +3,17 @@ use std::fs::File;
use crate::reader::{v4, v5, DumpReader, IndexReader};
use crate::Result;
use super::v3_to_v4::{CompatIndexV3ToV4, CompatV3ToV4};
use super::v5_to_v6::CompatV5ToV6;
pub struct CompatV4ToV5 {
from: v4::V4Reader,
pub enum CompatV4ToV5 {
V4(v4::V4Reader),
Compat(CompatV3ToV4),
}
impl CompatV4ToV5 {
pub fn new(v4: v4::V4Reader) -> CompatV4ToV5 {
CompatV4ToV5 { from: v4 }
CompatV4ToV5::V4(v4)
}
pub fn to_v6(self) -> CompatV5ToV6 {
@ -19,28 +21,52 @@ impl CompatV4ToV5 {
}
pub fn version(&self) -> crate::Version {
self.from.version()
match self {
CompatV4ToV5::V4(v4) => v4.version(),
CompatV4ToV5::Compat(compat) => compat.version(),
}
}
pub fn date(&self) -> Option<time::OffsetDateTime> {
self.from.date()
match self {
CompatV4ToV5::V4(v4) => v4.date(),
CompatV4ToV5::Compat(compat) => compat.date(),
}
}
pub fn instance_uid(&self) -> Result<Option<uuid::Uuid>> {
self.from.instance_uid()
match self {
CompatV4ToV5::V4(v4) => v4.instance_uid(),
CompatV4ToV5::Compat(compat) => compat.instance_uid(),
}
}
pub fn indexes(&self) -> Result<impl Iterator<Item = Result<CompatIndexV4ToV5>> + '_> {
Ok(self.from.indexes()?.map(|index_reader| -> Result<_> {
let compat = CompatIndexV4ToV5::new(index_reader?);
Ok(compat)
}))
pub fn indexes(&self) -> Result<Box<dyn Iterator<Item = Result<CompatIndexV4ToV5>> + '_>> {
let indexes = match self {
CompatV4ToV5::V4(v4) => Box::new(
v4.indexes()?
.map(|index| index.map(CompatIndexV4ToV5::from)),
)
as Box<dyn Iterator<Item = Result<CompatIndexV4ToV5>> + '_>,
CompatV4ToV5::Compat(compat) => Box::new(
compat
.indexes()?
.map(|index| index.map(CompatIndexV4ToV5::from)),
)
as Box<dyn Iterator<Item = Result<CompatIndexV4ToV5>> + '_>,
};
Ok(indexes)
}
pub fn tasks(
&mut self,
) -> Box<dyn Iterator<Item = Result<(v5::Task, Option<v5::UpdateFile>)>> + '_> {
Box::new(self.from.tasks().map(|task| {
let tasks = match self {
CompatV4ToV5::V4(v4) => v4.tasks(),
CompatV4ToV5::Compat(compat) => compat.tasks(),
};
Box::new(tasks.map(|task| {
task.map(|(task, content_file)| {
// let task_view: v4::tasks::TaskView = task.into();
@ -165,7 +191,11 @@ impl CompatV4ToV5 {
}
pub fn keys(&mut self) -> Box<dyn Iterator<Item = Result<v5::Key>> + '_> {
Box::new(self.from.keys().map(|key| {
let keys = match self {
CompatV4ToV5::V4(v4) => v4.keys(),
CompatV4ToV5::Compat(compat) => compat.keys(),
};
Box::new(keys.map(|key| {
key.map(|key| v5::Key {
description: key.description,
name: None,
@ -191,27 +221,47 @@ impl CompatV4ToV5 {
}
}
pub struct CompatIndexV4ToV5 {
from: v4::V4IndexReader,
pub enum CompatIndexV4ToV5 {
V4(v4::V4IndexReader),
Compat(CompatIndexV3ToV4),
}
impl From<v4::V4IndexReader> for CompatIndexV4ToV5 {
fn from(index_reader: v4::V4IndexReader) -> Self {
Self::V4(index_reader)
}
}
impl From<CompatIndexV3ToV4> for CompatIndexV4ToV5 {
fn from(index_reader: CompatIndexV3ToV4) -> Self {
Self::Compat(index_reader)
}
}
impl CompatIndexV4ToV5 {
pub fn new(v4: v4::V4IndexReader) -> CompatIndexV4ToV5 {
CompatIndexV4ToV5 { from: v4 }
}
pub fn metadata(&self) -> &crate::IndexMetadata {
self.from.metadata()
match self {
CompatIndexV4ToV5::V4(v4) => v4.metadata(),
CompatIndexV4ToV5::Compat(compat) => compat.metadata(),
}
}
pub fn documents(&mut self) -> Result<Box<dyn Iterator<Item = Result<v5::Document>> + '_>> {
self.from
.documents()
.map(|iter| Box::new(iter) as Box<dyn Iterator<Item = Result<v5::Document>> + '_>)
match self {
CompatIndexV4ToV5::V4(v4) => v4
.documents()
.map(|iter| Box::new(iter) as Box<dyn Iterator<Item = Result<v5::Document>> + '_>),
CompatIndexV4ToV5::Compat(compat) => compat
.documents()
.map(|iter| Box::new(iter) as Box<dyn Iterator<Item = Result<v5::Document>> + '_>),
}
}
pub fn settings(&mut self) -> Result<v5::Settings<v5::Checked>> {
Ok(v5::Settings::<v5::Unchecked>::from(self.from.settings()?).check())
match self {
CompatIndexV4ToV5::V4(v4) => Ok(v5::Settings::from(v4.settings()?).check()),
CompatIndexV4ToV5::Compat(compat) => Ok(v5::Settings::from(compat.settings()?).check()),
}
}
}

View File

@ -45,8 +45,8 @@ pub fn open(dump: impl Read) -> Result<Compat> {
// Version::V1 => Ok(Box::new(v1::Reader::open(path)?)),
Version::V1 => todo!(),
Version::V2 => todo!(),
Version::V3 => todo!(),
Version::V4 => todo!(),
Version::V3 => Ok(v3::V3Reader::open(path)?.to_v4().to_v5().to_v6().into()),
Version::V4 => Ok(v4::V4Reader::open(path)?.to_v5().to_v6().into()),
Version::V5 => Ok(v5::V5Reader::open(path)?.to_v6().into()),
Version::V6 => Ok(v6::V6Reader::open(path)?.into()),
}

View File

@ -3,7 +3,7 @@ use uuid::Uuid;
use super::Settings;
#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
#[cfg_attr(test, derive(serde::Serialize))]
pub struct IndexUuid {
pub uid: String,

View File

@ -34,7 +34,7 @@ use time::OffsetDateTime;
use uuid::Uuid;
pub mod errors;
mod meta;
pub mod meta;
pub mod settings;
pub mod updates;
@ -42,7 +42,7 @@ use crate::{IndexMetadata, Result, Version};
use self::meta::{DumpMeta, IndexUuid};
use super::{DumpReader, IndexReader};
use super::{compat::v3_to_v4::CompatV3ToV4, IndexReader};
pub type Document = serde_json::Map<String, serde_json::Value>;
pub type Settings<T> = settings::Settings<T>;
@ -63,7 +63,7 @@ pub type Setting<T> = settings::Setting<T>;
// everything related to the errors
// pub type ResponseError = errors::ResponseError;
pub type Code = meilisearch_types::error::Code;
pub type Code = errors::Code;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
@ -79,7 +79,7 @@ pub struct V3Reader {
dump: TempDir,
metadata: Metadata,
tasks: BufReader<File>,
index_uuid: Vec<IndexUuid>,
pub index_uuid: Vec<IndexUuid>,
}
impl V3Reader {
@ -103,9 +103,9 @@ impl V3Reader {
})
}
// pub fn to_v4(self) -> CompatV3ToV4 {
// CompatV3ToV4::new(self)
// }
pub fn to_v4(self) -> CompatV3ToV4 {
CompatV3ToV4::new(self)
}
pub fn version(&self) -> Version {
Version::V3

View File

@ -61,6 +61,13 @@ impl UpdateStatus {
}
}
pub fn is_finished(&self) -> bool {
match self {
UpdateStatus::Processing(_) | UpdateStatus::Enqueued(_) => false,
UpdateStatus::Aborted(_) | UpdateStatus::Failed(_) | UpdateStatus::Processed(_) => true,
}
}
pub fn processed(&self) -> Option<&Processed> {
match self {
UpdateStatus::Processed(p) => Some(p),

View File

@ -153,6 +153,8 @@ pub enum Code {
InvalidApiKeyIndexes,
InvalidApiKeyExpiresAt,
InvalidApiKeyDescription,
UnretrievableErrorCode,
}
impl Code {
@ -262,6 +264,9 @@ impl Code {
InvalidMinWordLengthForTypo => {
ErrCode::invalid("invalid_min_word_length_for_typo", StatusCode::BAD_REQUEST)
}
UnretrievableErrorCode => {
ErrCode::invalid("unretrievable_error_code", StatusCode::BAD_REQUEST)
}
}
}

View File

@ -19,10 +19,7 @@ use crate::{IndexMetadata, Result, Version};
use self::meta::{DumpMeta, IndexUuid};
use super::{
compat::v4_to_v5::CompatV4ToV5, /* compat::v4_to_v5::CompatV4ToV5, */ DumpReader,
IndexReader,
};
use super::{compat::v4_to_v5::CompatV4ToV5, DumpReader, IndexReader};
pub type Document = serde_json::Map<String, serde_json::Value>;
pub type Settings<T> = settings::Settings<T>;
@ -51,7 +48,7 @@ pub type IndexUid = meta::IndexUid;
// everything related to the errors
pub type ResponseError = errors::ResponseError;
pub type Code = meilisearch_types::error::Code;
pub type Code = errors::Code;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]