Skip to content

Commit

Permalink
explicitly declare innodb as storage engine for mysql databases & onl…
Browse files Browse the repository at this point in the history
…y index first 100 chars of index columns. closes #198
  • Loading branch information
dannyvankooten committed Dec 24, 2018
1 parent 67277ec commit 634baac
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ DROP INDEX unique_daily_page_stats ON daily_page_stats;
DROP INDEX unique_daily_referrer_stats ON daily_referrer_stats;

CREATE UNIQUE INDEX unique_daily_site_stats ON daily_site_stats(site_id, date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(site_id, hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(site_id, hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(site_id, hostname(100), pathname(100), date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(site_id, hostname(100), pathname(100), date);

-- +migrate Down

Expand All @@ -15,5 +15,5 @@ DROP INDEX unique_daily_page_stats ON daily_page_stats;
DROP INDEX unique_daily_referrer_stats ON daily_referrer_stats;

CREATE UNIQUE INDEX unique_daily_site_stats ON daily_site_stats(date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(hostname(100), pathname(100), date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(hostname(100), pathname(100), date);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CREATE TABLE hostnames(
id INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

-- +migrate Down
DROP TABLE IF EXISTS hostnames;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- +migrate Up
CREATE UNIQUE INDEX unique_hostnames_name ON hostnames(name);
CREATE UNIQUE INDEX unique_hostnames_name ON hostnames(name(100));

-- +migrate Down
DROP INDEX IF EXISTS unique_hostnames_name;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
CREATE TABLE pathnames(
id INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
name VARCHAR(255) NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

-- +migrate Down
DROP TABLE IF EXISTS pathnames;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- +migrate Up
CREATE UNIQUE INDEX unique_pathnames_name ON pathnames(name);
CREATE UNIQUE INDEX unique_pathnames_name ON pathnames(name(100));

-- +migrate Down
DROP INDEX IF EXISTS unique_pathnames_name;
14 changes: 7 additions & 7 deletions pkg/datastore/sqlstore/migrations/mysql/1_initial_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(255) NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

CREATE TABLE pageviews(
id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
Expand All @@ -18,7 +18,7 @@ CREATE TABLE pageviews(
referrer VARCHAR(255) NULL,
duration INT(4) NULL,
timestamp DATETIME NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

CREATE TABLE daily_page_stats(
hostname VARCHAR(255) NOT NULL,
Expand All @@ -29,7 +29,7 @@ CREATE TABLE daily_page_stats(
bounce_rate FLOAT NOT NULL,
avg_duration FLOAT NOT NULL,
date DATE NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

CREATE TABLE daily_site_stats(
pageviews INT NOT NULL,
Expand All @@ -38,7 +38,7 @@ CREATE TABLE daily_site_stats(
bounce_rate FLOAT NOT NULL,
avg_duration FLOAT NOT NULL,
date DATE NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

CREATE TABLE daily_referrer_stats(
url VARCHAR(255) NOT NULL,
Expand All @@ -47,12 +47,12 @@ CREATE TABLE daily_referrer_stats(
bounce_rate FLOAT NOT NULL,
avg_duration FLOAT NOT NULL,
date DATE NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

CREATE UNIQUE INDEX unique_user_email ON users(email);
CREATE UNIQUE INDEX unique_daily_site_stats ON daily_site_stats(date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(url, date);
CREATE UNIQUE INDEX unique_daily_page_stats ON daily_page_stats(hostname(100), pathname(100), date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(url(100), date);


-- +migrate Down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE referrer_stats(
known_durations INTEGER NOT NULL DEFAULT 0,
avg_duration FLOAT NOT NULL,
ts DATETIME NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;
INSERT INTO referrer_stats
SELECT site_id, hostname_id, pathname_id, groupname, pageviews, visitors, bounce_rate, known_durations, avg_duration, CONCAT(date, ' 00:00:00')
FROM daily_referrer_stats s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ALTER TABLE daily_referrer_stats ADD COLUMN pathname VARCHAR(255);
UPDATE daily_referrer_stats SET hostname = SUBSTRING_INDEX( url, "/", 3) WHERE url != "" AND ( hostname = "" OR hostname IS NULL);
UPDATE daily_referrer_stats SET pathname = REPLACE(url, hostname, "") WHERE url != "" AND (pathname = '' OR pathname IS NULL);

CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(hostname, pathname, date);
CREATE UNIQUE INDEX unique_daily_referrer_stats ON daily_referrer_stats(hostname(100), pathname(100), date);
ALTER TABLE daily_referrer_stats DROP COLUMN url;

-- +migrate Down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CREATE TABLE sites (
id INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
tracking_id VARCHAR(8) UNIQUE,
name VARCHAR(100) NOT NULL
) CHARACTER SET=utf8;
) CHARACTER SET=utf8 ENGINE=INNODB;

-- +migrate Down
DROP TABLE IF EXISTS sites;

0 comments on commit 634baac

Please sign in to comment.