sqlite.sql 6.23 KB
Newer Older
1 2 3 4 5
/**
 * This is the database schema for testing Sqlite support of Yii DAO and Active Record.
 * The database setup in config.php is required to perform then relevant tests:
 */

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

CREATE TABLE "profile" (
19 20 21 22 23
  id INTEGER NOT NULL,
  description varchar(128) NOT NULL,
  PRIMARY KEY (id)
);

24
CREATE TABLE "customer" (
25 26
  id INTEGER NOT NULL,
  email varchar(128) NOT NULL,
27
  name varchar(128),
28 29
  address text,
  status INTEGER DEFAULT 0,
30
  profile_id INTEGER,
31 32 33
  PRIMARY KEY (id)
);

34
CREATE TABLE "category" (
35 36 37 38 39
  id INTEGER NOT NULL,
  name varchar(128) NOT NULL,
  PRIMARY KEY (id)
);

40
CREATE TABLE "item" (
41 42 43 44 45 46
  id INTEGER NOT NULL,
  name varchar(128) NOT NULL,
  category_id INTEGER NOT NULL,
  PRIMARY KEY (id)
);

47
CREATE TABLE "order" (
48 49
  id INTEGER NOT NULL,
  customer_id INTEGER NOT NULL,
Alexander Kochetov committed
50
  created_at INTEGER NOT NULL,
51 52 53 54
  total decimal(10,0) NOT NULL,
  PRIMARY KEY (id)
);

55 56 57 58 59 60 61 62
CREATE TABLE "order_with_null_fk" (
  id INTEGER NOT NULL,
  customer_id INTEGER,
  created_at INTEGER NOT NULL,
  total decimal(10,0) NOT NULL,
  PRIMARY KEY (id)
);

63
CREATE TABLE "order_item" (
64 65 66 67 68 69 70
  order_id INTEGER NOT NULL,
  item_id INTEGER NOT NULL,
  quantity INTEGER NOT NULL,
  subtotal decimal(10,0) NOT NULL,
  PRIMARY KEY (order_id, item_id)
);

71 72 73 74
CREATE TABLE "order_item_with_null_fk" (
  order_id INTEGER,
  item_id INTEGER,
  quantity INTEGER NOT NULL,
75
  subtotal decimal(10,0) NOT NULL
76 77
);

78 79 80 81 82
CREATE TABLE "composite_fk" (
  id int(11) NOT NULL,
  order_id int(11) NOT NULL,
  item_id int(11) NOT NULL,
  PRIMARY KEY (id),
83
  CONSTRAINT FK_composite_fk_order_item FOREIGN KEY (order_id, item_id) REFERENCES "order_item" (order_id, item_id) ON DELETE CASCADE
84 85
);

86
CREATE TABLE "null_values" (
87 88 89 90 91 92 93
  id INTEGER UNSIGNED PRIMARY KEY NOT NULL,
  var1 INTEGER UNSIGNED,
  var2 INTEGER,
  var3 INTEGER DEFAULT NULL,
  stringcol VARCHAR(32) DEFAULT NULL
);

94
CREATE TABLE "type" (
95 96 97 98 99 100 101 102 103 104 105 106 107 108
  int_col INTEGER NOT NULL,
  int_col2 INTEGER 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'
);

109 110
INSERT INTO "profile" (description) VALUES ('profile customer 1');
INSERT INTO "profile" (description) VALUES ('profile customer 3');
111

112 113 114
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);
115

116 117
INSERT INTO "category" (name) VALUES ('Books');
INSERT INTO "category" (name) VALUES ('Movies');
118

119 120 121 122 123
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);
124

125 126 127
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);
128

129 130 131 132
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);

133 134 135 136 137 138
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);
139

140 141 142 143 144 145 146
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);

147
/**
148
 * (SqLite-)Database Schema for validator tests
149 150
 */

151 152
DROP TABLE IF EXISTS "validator_main";
DROP TABLE IF EXISTS "validator_ref";
153

154
CREATE TABLE "validator_main" (
Suralc committed
155 156
  id     INTEGER PRIMARY KEY ,
  field1 VARCHAR(255)
157 158
);

159
CREATE TABLE "validator_ref" (
Suralc committed
160
  id      INTEGER PRIMARY KEY ,
161
  a_field VARCHAR(255),
Suralc committed
162
  ref     INT(11)
163 164
);

165 166 167 168 169 170 171 172 173 174
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" (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO "validator_ref" (id, a_field, ref) VALUES (6, 'ref_to_5', 5);