mysql.sql 7.61 KB
Newer Older
w  
Qiang Xue committed
1
/**
Qiang Xue committed
2
 * This is the database schema for testing MySQL support of Yii DAO and Active Record.
3
 * The database setup in config.php is required to perform then relevant tests:
w  
Qiang Xue committed
4 5
 */

6 7
DROP TABLE IF EXISTS `composite_fk` CASCADE;
DROP TABLE IF EXISTS `order_item` CASCADE;
8
DROP TABLE IF EXISTS `order_item_with_null_fk` CASCADE;
9 10
DROP TABLE IF EXISTS `item` CASCADE;
DROP TABLE IF EXISTS `order` CASCADE;
11
DROP TABLE IF EXISTS `order_with_null_fk` CASCADE;
12 13 14 15 16 17
DROP TABLE IF EXISTS `category` CASCADE;
DROP TABLE IF EXISTS `customer` CASCADE;
DROP TABLE IF EXISTS `profile` CASCADE;
DROP TABLE IF EXISTS `null_values` CASCADE;
DROP TABLE IF EXISTS `type` CASCADE;
DROP TABLE IF EXISTS `constraints` CASCADE;
18 19

CREATE TABLE `constraints`
20 21 22 23 24
(
  `id` integer not null,
  `field1` varchar(255)
);

Qiang Xue committed
25

26
CREATE TABLE `profile` (
27 28 29 30 31
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `description` varchar(128) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

32
CREATE TABLE `customer` (
Qiang Xue committed
33 34
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(128) NOT NULL,
35
  `name` varchar(128),
Qiang Xue committed
36
  `address` text,
Qiang Xue committed
37
  `status` int (11) DEFAULT 0,
38
  `profile_id` int(11),
Qiang Xue committed
39 40 41
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

42
CREATE TABLE `category` (
Qiang Xue committed
43 44 45 46 47
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

48
CREATE TABLE `item` (
Qiang Xue committed
49 50 51 52 53
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  `category_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_item_category_id` (`category_id`),
54
  CONSTRAINT `FK_item_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
Qiang Xue committed
55 56
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

57
CREATE TABLE `order` (
Qiang Xue committed
58 59
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11) NOT NULL,
Alexander Kochetov committed
60
  `created_at` int(11) NOT NULL,
Qiang Xue committed
61
  `total` decimal(10,0) NOT NULL,
Qiang Xue committed
62
  PRIMARY KEY (`id`),
63
  CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE
Qiang Xue committed
64 65
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

66 67 68 69 70 71 72 73
CREATE TABLE `order_with_null_fk` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customer_id` int(11),
  `created_at` int(11) NOT NULL,
  `total` decimal(10,0) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

74
CREATE TABLE `order_item` (
Qiang Xue committed
75 76 77 78 79 80
  `order_id` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  `subtotal` decimal(10,0) NOT NULL,
  PRIMARY KEY (`order_id`,`item_id`),
  KEY `FK_order_item_item_id` (`item_id`),
81 82
  CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE,
  CONSTRAINT `FK_order_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) ON DELETE CASCADE
Qiang Xue committed
83 84
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

85 86 87 88 89 90 91 92

CREATE TABLE `order_item_with_null_fk` (
  `order_id` int(11),
  `item_id` int(11),
  `quantity` int(11) NOT NULL,
  `subtotal` decimal(10,0) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

93
CREATE TABLE `composite_fk` (
94 95 96 97
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
98
  CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `order_item` (`order_id`,`item_id`) ON DELETE CASCADE
99 100
);

101
CREATE TABLE null_values (
102 103 104 105 106 107 108 109
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `var1` INT UNSIGNED NULL,
  `var2` INT NULL,
  `var3` INT DEFAULT NULL,
  `stringcol` VARCHAR (32) DEFAULT NULL,
  PRIMARY KEY (id)
);

110
CREATE TABLE `type` (
Qiang Xue committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124
  `int_col` int(11) NOT NULL,
  `int_col2` int(11) DEFAULT '1',
  `char_col` char(100) NOT NULL,
  `char_col2` varchar(100) DEFAULT 'something',
  `char_col3` text,
  `float_col` double(4,3) NOT NULL,
  `float_col2` double DEFAULT '1.23',
  `blob_col` blob,
  `numeric_col` decimal(5,2) DEFAULT '33.22',
  `time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00',
  `bool_col` tinyint(1) NOT NULL,
  `bool_col2` tinyint(1) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

125 126
INSERT INTO `profile` (description) VALUES ('profile customer 1');
INSERT INTO `profile` (description) VALUES ('profile customer 3');
127

128 129 130
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
INSERT INTO `customer` (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
INSERT INTO `customer` (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
Qiang Xue committed
131

132 133
INSERT INTO `category` (name) VALUES ('Books');
INSERT INTO `category` (name) VALUES ('Movies');
Qiang Xue committed
134

135 136 137 138 139
INSERT INTO `item` (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO `item` (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO `item` (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO `item` (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO `item` (name, category_id) VALUES ('Cars', 2);
Qiang Xue committed
140

141 142 143
INSERT INTO `order` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO `order` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
Qiang Xue committed
144

145 146 147 148
INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO `order_with_null_fk` (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);

149 150 151 152 153 154
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO `order_item` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
155

156 157 158 159 160 161 162
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO `order_item_with_null_fk` (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);

163 164

/**
165
 * (MySQL-)Database Schema for validator tests
166 167
 */

168 169
DROP TABLE IF EXISTS `validator_main` CASCADE;
DROP TABLE IF EXISTS `validator_ref` CASCADE;
170

171
CREATE TABLE `validator_main` (
172 173 174 175 176
  `id`     INT(11) NOT NULL AUTO_INCREMENT,
  `field1` VARCHAR(255),
  PRIMARY KEY (`id`)
) ENGINE =InnoDB  DEFAULT CHARSET =utf8;

177
CREATE TABLE `validator_ref` (
178 179 180 181 182 183
  `id`      INT(11) NOT NULL AUTO_INCREMENT,
  `a_field` VARCHAR(255),
  `ref`     INT(11),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

184 185 186 187 188 189 190 191 192 193
INSERT INTO `validator_main` (id, field1) VALUES (1, 'just a string1');
INSERT INTO `validator_main` (id, field1) VALUES (2, 'just a string2');
INSERT INTO `validator_main` (id, field1) VALUES (3, 'just a string3');
INSERT INTO `validator_main` (id, field1) VALUES (4, 'just a string4');
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_3', 3);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO `validator_ref` (a_field, ref) VALUES ('ref_to_5', 5);