Skip to content
Snippets Groups Projects
Commit 3bb8a28b authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

fix: add unique field to IndexDef

parent 0aaf92fc
No related branches found
No related tags found
1 merge request!516OpDdl create space
...@@ -2,6 +2,8 @@ use crate::storage::set_pico_schema_version; ...@@ -2,6 +2,8 @@ use crate::storage::set_pico_schema_version;
use crate::traft; use crate::traft;
use crate::traft::op::Ddl; use crate::traft::op::Ddl;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::collections::BTreeMap;
use tarantool::{ use tarantool::{
index::Metadata as IndexMetadata, index::Metadata as IndexMetadata,
index::{IndexId, Part}, index::{IndexId, Part},
...@@ -115,6 +117,7 @@ pub struct IndexDef { ...@@ -115,6 +117,7 @@ pub struct IndexDef {
pub parts: Vec<Part>, pub parts: Vec<Part>,
pub schema_version: u64, pub schema_version: u64,
pub operable: bool, pub operable: bool,
pub unique: bool,
} }
impl Encode for IndexDef {} impl Encode for IndexDef {}
...@@ -125,12 +128,14 @@ impl IndexDef { ...@@ -125,12 +128,14 @@ impl IndexDef {
pub fn to_index_metadata(&self) -> IndexMetadata { pub fn to_index_metadata(&self) -> IndexMetadata {
use tarantool::index::IndexType; use tarantool::index::IndexType;
let mut opts = BTreeMap::new();
opts.insert(Cow::from("unique"), Value::Bool(self.unique));
let index_meta = IndexMetadata { let index_meta = IndexMetadata {
space_id: self.space_id, space_id: self.space_id,
index_id: self.id, index_id: self.id,
name: self.name.as_str().into(), name: self.name.as_str().into(),
r#type: IndexType::Tree, r#type: IndexType::Tree,
opts: Default::default(), opts,
parts: self.parts.clone(), parts: self.parts.clone(),
}; };
......
...@@ -1392,6 +1392,7 @@ impl Indexes { ...@@ -1392,6 +1392,7 @@ impl Indexes {
.field(("parts", FieldType::Array)) .field(("parts", FieldType::Array))
.field(("schema_version", FieldType::Unsigned)) .field(("schema_version", FieldType::Unsigned))
.field(("operable", FieldType::Boolean)) .field(("operable", FieldType::Boolean))
.field(("unique", FieldType::Boolean))
.if_not_exists(true) .if_not_exists(true)
.create()?; .create()?;
......
...@@ -972,6 +972,7 @@ impl NodeImpl { ...@@ -972,6 +972,7 @@ impl NodeImpl {
parts: primary_key, parts: primary_key,
operable: false, operable: false,
// TODO: support other cases // TODO: support other cases
unique: true,
local: true, local: true,
}; };
self.storage.indexes.insert(&index_def)?; self.storage.indexes.insert(&index_def)?;
......
...@@ -87,6 +87,7 @@ def test_ddl_create_space_bulky(cluster: Cluster): ...@@ -87,6 +87,7 @@ def test_ddl_create_space_bulky(cluster: Cluster):
[[1, "unsigned", None, None, None]], [[1, "unsigned", None, None, None]],
2, 2,
True, True,
True,
] ]
assert i1.call("box.space._pico_index:get", [666, 0]) == index_info assert i1.call("box.space._pico_index:get", [666, 0]) == index_info
assert i2.call("box.space._pico_index:get", [666, 0]) == index_info assert i2.call("box.space._pico_index:get", [666, 0]) == index_info
...@@ -96,7 +97,7 @@ def test_ddl_create_space_bulky(cluster: Cluster): ...@@ -96,7 +97,7 @@ def test_ddl_create_space_bulky(cluster: Cluster):
0, 0,
"primary_key", "primary_key",
"tree", "tree",
dict(), dict(unique=True),
[[1, "unsigned", None, None, None]], [[1, "unsigned", None, None, None]],
] ]
assert i1.call("box.space._index:get", [666, 0]) == index_meta assert i1.call("box.space._index:get", [666, 0]) == index_meta
...@@ -208,7 +209,7 @@ def test_ddl_from_snapshot(cluster: Cluster): ...@@ -208,7 +209,7 @@ def test_ddl_from_snapshot(cluster: Cluster):
0, 0,
"primary_key", "primary_key",
"tree", "tree",
dict(), dict(unique=True),
[[1, "unsigned", None, None, None]], [[1, "unsigned", None, None, None]],
] ]
assert i1.call("box.space._index:get", [666, 0]) == index_meta assert i1.call("box.space._index:get", [666, 0]) == index_meta
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment