# -*- mode: sql; sql-product: mysql -*-
#
# Copyright(C) 2021  Sutou Kouhei <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

--source ../../../../include/mroonga/have_mroonga.inc
--source ../../../../include/mroonga/have_groonga_11_0_1_or_later.inc

--disable_warnings
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS attributes;
--enable_warnings

SET NAMES utf8mb4;

CREATE TABLE attributes (
  id varchar(255) PRIMARY KEY,
  name varchar(255),
  value varchar(255)
) DEFAULT CHARSET=utf8mb4;

CREATE TABLE items (
  id int PRIMARY KEY AUTO_INCREMENT,
  attributes text DEFAULT NULL COMMENT "flags 'COLUMN_VECTOR', groonga_type 'attributes'"
) DEFAULT CHARSET=utf8mb4;

INSERT INTO items (attributes)
  VALUES ('[{"_key": "item-1-1", "name": "color", "value": "white"},
            {"_key": "item-1-2", "name": "size",  "value": "big"}]');
INSERT INTO items (attributes)
  VALUES ('[{"_key": "item-2-1", "name": "color", "value": "black"}]');
INSERT INTO items (attributes) VALUES ('');

SELECT * FROM attributes;

INSERT INTO items (attributes)
  VALUES ('["ITEM-1-1","ITEM-1-2"]');
INSERT INTO items (attributes)
  VALUES ('["ITEM-2-1"]');

DROP TABLE items;
DROP TABLE attributes;

--source ../../../../include/mroonga/have_mroonga_deinit.inc
