BEGIN;

ALTER TABLE activity_stream_stats_daily ADD COLUMN date DATE;
UPDATE activity_stream_stats_daily SET date = TRUNC(receive_at);
ALTER TABLE activity_stream_stats_daily ALTER COLUMN date SET NOT NULL;

ALTER TABLE activity_stream_stats_daily ADD COLUMN page VARCHAR(16) NOT NULL;

ALTER TABLE activity_stream_stats_daily DROP COLUMN click_position;

ALTER TABLE activity_stream_stats_daily DROP COLUMN source;

CREATE TABLE activity_stream_events_daily (
    client_id VARCHAR(64) NOT NULL,
    tab_id VARCHAR(64) NOT NULL,
    addon_version VARCHAR(16) NOT NULL,
    source VARCHAR(64) NOT NULL,
    page VARCHAR(16) NOT NULL,
    action_position VARCHAR(16) NOT NULL,
    event VARCHAR(16) NOT NULL,
    receive_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
    date DATE NOT NULL,
    locale VARCHAR(14) NOT NULL,
    country_code VARCHAR(5) NOT NULL,
    os VARCHAR(64) NOT NULL,
    browser VARCHAR(64) NOT NULL,
    version VARCHAR(64) NOT NULL,
    device VARCHAR(64) NOT NULL
);

COMMIT;

BEGIN;

ALTER TABLE activity_stream_stats_daily ADD COLUMN date DATE DEFAULT CURRENT_DATE NOT NULL;
UPDATE activity_stream_stats_daily SET date = TRUNC(receive_at);

ALTER TABLE activity_stream_stats_daily ADD COLUMN page VARCHAR(16) DEFAULT 'newtab' NOT NULL;

ALTER TABLE activity_stream_stats_daily DROP COLUMN click_position;

ALTER TABLE activity_stream_stats_daily DROP COLUMN source;

CREATE TABLE activity_stream_events_daily (
    client_id VARCHAR(64) NOT NULL,
    tab_id VARCHAR(64) NOT NULL,
    addon_version VARCHAR(16) NOT NULL,
    source VARCHAR(64) NOT NULL,
    page VARCHAR(16) NOT NULL,
    action_position VARCHAR(16) NOT NULL,
    event VARCHAR(16) NOT NULL,
    receive_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
    date DATE NOT NULL,
    locale VARCHAR(14) NOT NULL,
    country_code VARCHAR(5) NOT NULL,
    os VARCHAR(64) NOT NULL,
    browser VARCHAR(64) NOT NULL,
    version VARCHAR(64) NOT NULL,
    device VARCHAR(64) NOT NULL
);

COMMIT;

Fix the migration SQL script for Redshift
Fix the migration SQL script for Redshift

Close #337

Squashed commit of the following:

commit 64957592abd8c236f58f4dee20d24f338dd9078a
Author: Nan Jiang <njiang028@gmail.com>
Date:   Mon Apr 4 20:27:20 2016 -0400

    Fix migration script for redshift
