]> git.imager.perl.org - bse.git/blobdiff - schema/bse.sql
custom data database fields
[bse.git] / schema / bse.sql
index 307309c4f177353c83f8299a7bfae7b629432de3..ac893bb6a1582be3575010a10622adf33f7dc99f 100644 (file)
@@ -1,3 +1,10 @@
+drop table if exists bse_tag_category_deps;
+drop table if exists bse_tag_categories;
+drop table if exists bse_tag_members;
+drop table if exists bse_tags;
+drop table if exists bse_coupon_tiers;
+drop table if exists bse_coupons;
+
 -- represents sections, articles
 DROP TABLE IF EXISTS article;
 CREATE TABLE article (
@@ -99,6 +106,8 @@ CREATE TABLE article (
 
   -- alias used to generate links
   linkAlias varchar(255) not null default '',
+
+  category varchar(40) not null default '',
   
   PRIMARY KEY (id),
 
@@ -127,7 +136,7 @@ CREATE TABLE searchindex (
   sectionIds varchar(255) default '' not null,
   scores varchar(255) default '' not null,
   PRIMARY KEY (id)
-);
+) engine=myisam;
 
 #
 # Table structure for table 'image'
@@ -334,9 +343,28 @@ create table orders (
 
   stage varchar(20) not null default '',
 
+  -- truncated credit card number
+  ccPAN varchar(4) not null default '',
+
+  -- true if the order was paid manually
+  paid_manually integer not null default 0,
+
+  coupon_id integer null,
+  -- obsolete
+  coupon_code_discount_pc real null default 0,
+
+  delivery_in integer null,
+
+  product_cost_discount integer not null default 0,
+
+  coupon_cart_wide integer not null default 1,
+
+  coupon_description varchar(255) not null default '',
+
   primary key (id),
   index order_cchash(ccNumberHash),
-  index order_userId(userId, orderDate)
+  index order_userId(userId, orderDate),
+  index order_coupon(coupon_id)
 );
 
 DROP TABLE IF EXISTS order_item;
@@ -381,9 +409,16 @@ create table order_item (
 
   product_code varchar(80) not null default '',
 
+  tier_id integer null default null,
+
+  product_discount integer not null default 0,
+  product_discount_units integer not null default 0,
+
+  custom_data blob null,
+
   primary key (id),
   index order_item_order(orderId, id)
-);
+) engine=InnoDB;
 
 drop table if exists other_parents;
 create table other_parents (
@@ -460,6 +495,7 @@ create table article_files (
   primary key (id)
 );
 
+-- this now stores metadata for more than just files
 drop table if exists bse_article_file_meta;
 create table bse_article_file_meta (
   id integer not null auto_increment primary key,
@@ -477,7 +513,10 @@ create table bse_article_file_meta (
   -- regenerated
   appdata integer not null default 0,
 
-  unique file_name(file_id, name)
+  -- owner type
+  owner_type varchar(20) not null default 'bse_file',
+
+  unique file_name(file_id, owner_type, name)
 );
 
 -- these are mailing list subscriptions
@@ -544,33 +583,35 @@ create table subscribed_users (
 
 -- contains web site users
 -- there will be a separate admin users table at some point
-drop table if exists site_users;
-create table site_users (
+drop table if exists bse_siteusers;
+create table bse_siteusers (
   id integer not null auto_increment,
 
+  idUUID varchar(40) not null,
+
   userId varchar(40) not null,
   password varchar(255) not null,
+  password_type varchar(20) not null default 'plain',
+
   email varchar(255) not null,
 
-  keepAddress integer not null default 1,
   whenRegistered datetime not null,
   lastLogon datetime not null,
 
   -- used to fill in the checkout form
+  title varchar(127),
   name1 varchar(127),
   name2 varchar(127),
-  address varchar(127),
-  city varchar(127),
+  street varchar(127),
+  street2 varchar(127),
+  suburb varchar(127),
   state varchar(40),
   postcode varchar(40),
+  country varchar(127),
   telephone varchar(80),
   facsimile varchar(80),
-  country varchar(127),
-
-  -- the user wants to receive the site newsletter if any
-  -- this should default to NO
-  -- this is probably ignored for now
-  wantLetter integer not null default 0,
+  mobile varchar(80) not null default '',
+  organization varchar(127),
 
   -- if this is non-zero, we have permission to send email to this
   -- user
@@ -585,31 +626,25 @@ create table site_users (
 
   textOnlyMail integer not null,
 
-  title varchar(127),
-  organization varchar(127),
-  
-  referral integer,
-  otherReferral varchar(127) not null,
-  prompt integer,
-  otherPrompt varchar(127) not null,
-  profession integer not null,
-  otherProfession varchar(127) not null,
-
   previousLogon datetime not null,
 
-  -- used for billing information on the checkout form
-  billFirstName varchar(127) not null default '',
-  billLastName varchar(127) not null default '',
-  billStreet varchar(127) not null default '',
-  billSuburb varchar(127) not null default '',
-  billState varchar(40) not null default '',
-  billPostCode varchar(40) not null default '',
-  billCountry varchar(127) not null default '',
+  -- used for shipping information on the checkout form
+  delivTitle varchar(127),
+  delivEmail varchar(255) not null default '',
+  delivFirstName varchar(127) not null default '',
+  delivLastName varchar(127) not null default '',
+  delivStreet varchar(127) not null default '',
+  delivStreet2 varchar(127) not null default '',
+  delivSuburb varchar(127) not null default '',
+  delivState varchar(40) not null default '',
+  delivPostCode varchar(40) not null default '',
+  delivCountry varchar(127) not null default '',
+  delivTelephone varchar(80) not null default '',
+  delivFacsimile varchar(80) not null default '',
+  delivMobile varchar(80) not null default '',
+  delivOrganization varchar(127),
 
   instructions text not null default '',
-  billTelephone varchar(80) not null default '',
-  billFacsimile varchar(80) not null default '',
-  billEmail varchar(255) not null default '',
 
   adminNotes text not null default '',
 
@@ -617,6 +652,16 @@ create table site_users (
 
   flags varchar(80) not null default '',
 
+  affiliate_name varchar(40) not null default '',
+
+  -- for password recovery
+  -- number of attempts today
+  lost_today integer not null default 0,
+  -- what today refers to
+  lost_date date null,
+  -- the hash the customer needs to supply to change their password
+  lost_id varchar(32) null,
+
   customText1 text,
   customText2 text,
   customText3 text,
@@ -624,32 +669,18 @@ create table site_users (
   customStr2 varchar(255),
   customStr3 varchar(255),
 
-  affiliate_name varchar(40) not null default '',
-
-  delivMobile varchar(80) not null default '',
-  billMobile varchar(80) not null default '',
-
-  delivStreet2 varchar(127) not null default '',
-  billStreet2 varchar(127) not null default '',
-
-  billOrganization varchar(127) not null default '',
-
   customInt1 integer,
   customInt2 integer,
 
-  password_type varchar(20) not null default 'plain',
+  customWhen1 datetime,
 
-  -- for password recovery
-  -- number of attempts today
-  lost_today integer not null default 0,
-  -- what today refers to
-  lost_date date null,
-  -- the hash the customer needs to supply to change their password
-  lost_id varchar(32) null,
+  -- when the account lock-out (if any) ends
+  lockout_end datetime,
 
   primary key (id),
   unique (userId),
-  index (affiliate_name)
+  index (affiliate_name),
+  unique (idUUID)
 );
 
 -- this is used to track email addresses that we've sent subscription
@@ -721,6 +752,10 @@ create table admin_users (
   password varchar(255) not null,
   perm_map varchar(255) not null,
   password_type varchar(20) not null default 'plain',
+
+  -- when the account lock-out (if any) ends
+  lockout_end datetime,
+
   primary key (base_id),
   unique (logon)
 );
@@ -898,8 +933,9 @@ create table bse_product_options (
   display_order integer not null,
   enabled integer not null default 0,
   default_value integer,
+  custom_data blob null,
   index product_order(product_id, display_order)
-) type=innodb;
+) engine=innodb;
 
 drop table if exists bse_product_option_values;
 create table bse_product_option_values (
@@ -907,8 +943,9 @@ create table bse_product_option_values (
   product_option_id integer not null references bse_product_options(id),
   value varchar(255) not null,
   display_order integer not null,
+  custom_data blob null,
   index option_order(product_option_id, display_order)
-) type=innodb;
+) engine=innodb;
 
 drop table if exists bse_order_item_options;
 create table bse_order_item_options (
@@ -919,8 +956,9 @@ create table bse_order_item_options (
   value varchar(40) not null,
   display varchar(80) not null,
   display_order integer not null,
+  custom_data blob null,
   index item_order(order_item_id, display_order)
-) type=innodb;
+) engine=innodb;
 
 drop table if exists bse_owned_files;
 create table bse_owned_files (
@@ -1227,7 +1265,7 @@ create table bse_files (
   ftype varchar(20) not null default 'img',
 
   index owner(file_type, owner_id)
-) type = InnoDB;
+) engine = InnoDB;
 
 -- a generic selection of files from a pool
 create table bse_selected_files (
@@ -1243,7 +1281,7 @@ create table bse_selected_files (
   display_order integer not null default -1,
 
   unique only_one(owner_id, owner_type, file_id)
-) type = InnoDB;
+) engine = InnoDB;
 
 drop table if exists bse_price_tiers;
 create table bse_price_tiers (
@@ -1257,7 +1295,7 @@ create table bse_price_tiers (
   to_date date null,
 
   display_order integer null null
-);
+) engine=innodb;
 
 drop table if exists bse_price_tier_prices;
 
@@ -1270,5 +1308,108 @@ create table bse_price_tier_prices (
   retailPrice integer not null,
 
   unique tier_product(tier_id, product_id)
+) engine=InnoDB;
+
+create table bse_tags (
+  id integer not null auto_increment primary key,
+
+  -- typically "BA" for BSE article
+  owner_type char(2) not null,
+  cat varchar(80) not null,
+  val varchar(80) not null,
+
+  unique cat_val(owner_type, cat, val)
+);
+
+create table bse_tag_members (
+  id integer not null auto_increment primary key,
+
+  -- typically BA for BSE article
+  owner_type char(2) not null,
+  owner_id integer not null,
+  tag_id integer not null,
+
+  unique art_tag(owner_id, tag_id),
+  index by_tag(tag_id)
+);
+
+create table bse_tag_categories (
+  id integer not null auto_increment primary key,
+
+  cat varchar(80) not null,
+
+  owner_type char(2) not null,
+
+  unique cat(cat, owner_type)
 );
 
+create table bse_tag_category_deps (
+  id integer not null auto_increment primary key,
+
+  cat_id integer not null,
+
+  depname varchar(160) not null,
+
+  unique cat_dep(cat_id, depname)
+);
+
+drop table if exists bse_ip_lockouts;
+create table bse_ip_lockouts (
+  id integer not null auto_increment primary key,
+
+  ip_address varchar(20) not null,
+
+  -- S or A for site user or admin user lockouts
+  type char not null,
+
+  expires datetime not null,
+
+  unique ip_address(ip_address, type)
+) engine=innodb;
+
+create table bse_coupons (
+  id integer not null auto_increment primary key,
+
+  code varchar(40) not null,
+
+  description text not null,
+
+  `release` date not null,
+
+  expiry date not null,
+
+  discount_percent real null,
+
+  campaign varchar(20) not null,
+
+  last_modified datetime not null,
+
+  untiered integer not null default 0,
+
+  classid varchar(20) not null default 'bse_simple',
+
+  config blob not null,
+
+  unique codes(code)
+) engine=InnoDB;
+
+create table bse_coupon_tiers (
+  id integer not null auto_increment primary key,
+
+  coupon_id integer not null,
+
+  tier_id integer not null,
+
+  unique (coupon_id, tier_id),
+
+  foreign key (coupon_id) references bse_coupons(id)
+    on delete cascade on update restrict,
+
+  foreign key (tier_id) references bse_price_tiers(id)
+    on delete cascade on update restrict
+) engine=InnoDB;
+
+alter table order_item add constraint tier_id
+  foreign key (tier_id) references bse_price_tiers(id)
+    on delete restrict on update restrict;
+