<?php

use Phalcon\Mvc\Model\Migration;

class WordCloudMigration_444 extends Migration {
    public function up()
    {
        $this->down();

        self::$connection->execute("
            CREATE TABLE jaga.word_cloud_stop_words (
              id bigserial NOT NULL,
              word character varying(255) NOT NULL,
              PRIMARY KEY (id)
            )
            WITH (
                OIDS = FALSE
            );
        ");

        $sql = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'word_cloud_stop_words.sql');
        self::$connection->execute($sql);

        self::$connection->execute("
            CREATE TABLE jaga.word_cloud (
              id bigserial NOT NULL,
              category character varying(255) NOT NULL,
              date timestamp without time zone NOT NULL,
              word character varying(255) NOT NULL,
              word_count int NOT NULL,
              PRIMARY KEY (id)
            )
            WITH (
                OIDS = FALSE
            );
        ");

        self::$connection->execute("
            CREATE TABLE jaga.api_tracker (
              id bigserial NOT NULL,
              name character varying(255) NOT NULL,
              last_update_date timestamp without time zone NOT NULL,
              PRIMARY KEY (id)
            )
            WITH (
                OIDS = FALSE
            );
        ");
    }

    public function down()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.api_tracker;
        ");

        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.word_cloud;
        ");

        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.word_cloud_stop_words;
        ");
    }
}
