postgres.sql 5.3 KB
Newer Older
w  
Qiang Xue committed
1 2
/**
 * This is the database schema for testing PostgreSQL support of yii Active Record.
3 4
 * To test this feature, you need to create a database named 'yiitest' on 'localhost'
 * and create an account 'postgres/postgres' which owns this test database.
w  
Qiang Xue committed
5 6
 */

7 8 9 10 11
DROP TABLE IF EXISTS tbl_order_item CASCADE;
DROP TABLE IF EXISTS tbl_item CASCADE;
DROP TABLE IF EXISTS tbl_order CASCADE;
DROP TABLE IF EXISTS tbl_category CASCADE;
DROP TABLE IF EXISTS tbl_customer CASCADE;
12
DROP TABLE IF EXISTS tbl_profile CASCADE;
13
DROP TABLE IF EXISTS tbl_type CASCADE;
14
DROP TABLE IF EXISTS tbl_null_values CASCADE;
15 16 17 18 19 20 21
DROP TABLE IF EXISTS tbl_constraints CASCADE;

CREATE TABLE tbl_constraints
(
  id integer not null,
  field1 varchar(255)
);
22

23 24 25 26 27
CREATE TABLE tbl_profile (
  id serial not null primary key,
  description varchar(128) NOT NULL
);

28 29 30
CREATE TABLE tbl_customer (
  id serial not null primary key,
  email varchar(128) NOT NULL,
31
  name varchar(128),
32
  address text,
33 34
  status integer DEFAULT 0,
  profile_id integer
w  
Qiang Xue committed
35 36
);

37 38
comment on column public.tbl_customer.email is 'someone@example.com';

39 40 41
CREATE TABLE tbl_category (
  id serial not null primary key,
  name varchar(128) NOT NULL
w  
Qiang Xue committed
42 43
);

44 45 46 47
CREATE TABLE tbl_item (
  id serial not null primary key,
  name varchar(128) NOT NULL,
  category_id integer NOT NULL references tbl_category(id) on UPDATE CASCADE on DELETE CASCADE
w  
Qiang Xue committed
48 49
);

50 51 52
CREATE TABLE tbl_order (
  id serial not null primary key,
  customer_id integer NOT NULL references tbl_customer(id) on UPDATE CASCADE on DELETE CASCADE,
Alexander Kochetov committed
53
  created_at integer NOT NULL,
54
  total decimal(10,0) NOT NULL
w  
Qiang Xue committed
55 56
);

57 58 59 60 61 62
CREATE TABLE tbl_order_item (
  order_id integer NOT NULL references tbl_order(id) on UPDATE CASCADE on DELETE CASCADE,
  item_id integer NOT NULL references tbl_item(id) on UPDATE CASCADE on DELETE CASCADE,
  quantity integer NOT NULL,
  subtotal decimal(10,0) NOT NULL,
  PRIMARY KEY (order_id,item_id)
w  
Qiang Xue committed
63 64
);

65
CREATE TABLE tbl_null_values (
66 67
  id INT NOT NULL,
  var1 INT NULL,
68 69 70 71 72 73
  var2 INT NULL,
  var3 INT DEFAULT NULL,
  stringcol VARCHAR(32) DEFAULT NULL,
  PRIMARY KEY (id)
);

74 75 76 77 78 79 80 81 82 83 84 85 86
CREATE TABLE tbl_type (
  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 precision NOT NULL,
  float_col2 double precision DEFAULT '1.23',
  blob_col bytea,
  numeric_col decimal(5,2) DEFAULT '33.22',
  time timestamp NOT NULL DEFAULT '2002-01-01 00:00:00',
  bool_col smallint NOT NULL,
  bool_col2 smallint DEFAULT '1'
w  
Qiang Xue committed
87 88
);

89 90 91 92
INSERT INTO tbl_profile (description) VALUES ('profile customer 1');
INSERT INTO tbl_profile (description) VALUES ('profile customer 3');

INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user1@example.com', 'user1', 'address1', 1, 1);
93
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user2@example.com', 'user2', 'address2', 1);
94
INSERT INTO tbl_customer (email, name, address, status, profile_id) VALUES ('user3@example.com', 'user3', 'address3', 2, 2);
95 96 97 98 99 100 101 102 103 104

INSERT INTO tbl_category (name) VALUES ('Books');
INSERT INTO tbl_category (name) VALUES ('Movies');

INSERT INTO tbl_item (name, category_id) VALUES ('Agile Web Application Development with Yii1.1 and PHP5', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Yii 1.1 Application Development Cookbook', 1);
INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Toy Story', 2);
INSERT INTO tbl_item (name, category_id) VALUES ('Cars', 2);

Alexander Kochetov committed
105 106 107
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (1, 1325282384, 110.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325334482, 33.0);
INSERT INTO tbl_order (customer_id, created_at, total) VALUES (2, 1325502201, 40.0);
108 109 110 111 112 113 114

INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 1, 1, 30.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2, 2, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
115 116

/**
117
 * (Postgres-)Database Schema for validator tests
118 119
 */

120 121
DROP TABLE IF EXISTS tbl_validator_main CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE;
122

123
CREATE TABLE tbl_validator_main (
124 125 126 127
  id integer not null primary key,
  field1 VARCHAR(255)
);

128
CREATE TABLE tbl_validator_ref (
129 130 131 132 133
  id integer not null primary key,
  a_field VARCHAR(255),
  ref     integer
);

134 135 136 137 138 139 140 141 142
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
Alexander Kochetov committed
143
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5);