func (m *Migration) Up_20150805095630_CreateQueuesTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`
		CREATE TABLE queues (
			id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'キュー ID',
			user_id INT UNSIGNED NOT NULL COMMENT 'ユーザ ID',
			tweet_id VARCHAR(20) NOT NULL COMMENT 'ツイート ID',
			status ENUM(
				'canceled',
				'ready',
				'locked',
				'completed',
				'failed'
			) NOT NULL DEFAULT 'ready' COMMENT '状態',
			action ENUM(
				'retweet',
				'tweet',
				'favorite'
			) NOT NULL DEFAULT 'retweet' COMMENT '実行内容',
			execute_time INT UNSIGNED NOT NULL COMMENT '実行時刻',
			fail_count INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '失敗回数',
			created_at DATETIME COMMENT '作成日時',
			updated_at DATETIME COMMENT '更新日時',
			PRIMARY KEY (id),
			UNIQUE INDEX user_id_tweet_id_action_UNIQUE (user_id, tweet_id, action)
		) ENGINE = InnoDB DEFAULT CHARSET 'utf8mb4'
	`); err != nil {
		panic(err)
	}
}
func (m *Migration) Up_20150813022509_CreateTweetsTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`
		CREATE TABLE tweets (
			id VARCHAR(20) NOT NULL COMMENT 'ツイート ID',
			text TEXT NOT NULL COMMENT 'ツイート内容',
			sent_at DATETIME NOT NULL COMMENT '投稿日時',
			PRIMARY KEY (id)
		) ENGINE = InnoDB DEFAULT CHARSET 'utf8mb4'
	`); err != nil {
		panic(err)
	}
}
Esempio n. 3
0
func getSequence(db *genmai.DB) (uint64, error) {
	tx, err := db.DB().Begin()
	if err != nil {
		return 0, err
	}
	st, err := tx.Prepare("UPDATE seq set id = LAST_INSERT_ID(id + 1)")
	if err != nil {
		return 0, err
	}
	defer st.Close()
	st.Exec()
	stmt, err := tx.Prepare("SELECT LAST_INSERT_ID()")
	defer stmt.Close()
	var id uint64
	err = stmt.QueryRow().Scan(&id)
	if err != nil {
		return 0, err
	}
	return id, nil
}
func (m *Migration) Up_20150805072506_CreateUsersTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`
		CREATE TABLE users (
			id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ユーザ ID',
			twitter_id VARCHAR(20) CHARACTER SET 'ascii' COLLATE 'ascii_bin' NOT NULL COMMENT 'Twitter ID',
			screen_name VARCHAR(15) CHARACTER SET 'ascii' COLLATE 'ascii_general_ci' NOT NULL COMMENT 'ユーザ名',
			access_token VARCHAR(255) CHARACTER SET 'ascii' COLLATE 'ascii_bin' NOT NULL COMMENT 'アクセストークン',
			access_token_secret VARCHAR(255) CHARACTER SET 'ascii' COLLATE 'ascii_bin' NOT NULL COMMENT 'アクセストークンシークレット',
			enable TINYINT(1) NOT NULL DEFAULT 0 COMMENT '使用許可(0=不,1=可)',
			created_at DATETIME COMMENT '作成日時',
			updated_at DATETIME COMMENT '更新日時',
			PRIMARY KEY (id),
			UNIQUE INDEX twitter_id_UNIQUE (twitter_id),
			UNIQUE INDEX screen_name_UNIQUE (screen_name),
			UNIQUE INDEX access_token_UNIQUE (access_token)
		) ENGINE = InnoDB DEFAULT CHARSET 'utf8mb4'
	`); err != nil {
		panic(err)
	}
}
func (m *Migration) Down_20150813022509_CreateTweetsTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`DROP TABLE tweets`); err != nil {
		panic(err)
	}
}
func (m *Migration) Down_20150805072506_CreateUsersTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`DROP TABLE users`); err != nil {
		panic(err)
	}
}
func (m *Migration) Down_20150805095630_CreateQueuesTable(tx *genmai.DB) {
	if _, err := tx.DB().Exec(`DROP TABLE queues`); err != nil {
		panic(err)
	}
}