summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190710103736_create_queue_tables.rb44
-rw-r--r--db/schema.rb15
-rw-r--r--db/seeds.rb4
3 files changed, 62 insertions, 1 deletions
diff --git a/db/migrate/20190710103736_create_queue_tables.rb b/db/migrate/20190710103736_create_queue_tables.rb
new file mode 100644
index 00000000000..9dd36753851
--- /dev/null
+++ b/db/migrate/20190710103736_create_queue_tables.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class CreateQueueTables < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ # When a migration requires downtime you **must** uncomment the following
+ # constant and define a short and easy to understand explanation as to why the
+ # migration requires downtime.
+ # DOWNTIME_REASON = ''
+
+ # When using the methods "add_concurrent_index", "remove_concurrent_index" or
+ # "add_column_with_default" you must disable the use of transactions
+ # as these methods can not run in an existing transaction.
+ # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
+ # that either of them is the _only_ method called in the migration,
+ # any other changes should go in a separate migration.
+ # This ensures that upon failure _only_ the index creation or removing fails
+ # and can be retried or reverted easily.
+ #
+ # To disable transactions uncomment the following line and remove these
+ # comments:
+ # disable_ddl_transaction!
+
+ def change
+ create_table :jobs do |t|
+ t.datetime :scheduled_for, null: false
+ end
+
+ add_index :jobs, [:scheduled_for, :id]
+
+ create_table :job_logs do |t|
+ t.references :job, index: true, foreign_key: { on_delete: :cascade }, null: false
+ t.datetime :started_at, null: false
+ t.datetime :finished_at, null: false
+ t.string :scheduler
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9a8b64689bd..b9c75992ecc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20190703130053) do
+ActiveRecord::Schema.define(version: 20190710103736) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1722,6 +1722,18 @@ ActiveRecord::Schema.define(version: 20190703130053) do
t.index ["service_id"], name: "index_jira_tracker_data_on_service_id", using: :btree
end
+ create_table "job_logs", force: :cascade do |t|
+ t.bigint "job_id", null: false
+ t.datetime "started_at", null: false
+ t.datetime "finished_at", null: false
+ t.index ["job_id"], name: "index_job_logs_on_job_id", using: :btree
+ end
+
+ create_table "jobs", force: :cascade do |t|
+ t.datetime "scheduled_for", null: false
+ t.index ["scheduled_for"], name: "index_jobs_on_scheduled_for", using: :btree
+ end
+
create_table "keys", id: :serial, force: :cascade do |t|
t.integer "user_id"
t.datetime "created_at"
@@ -3748,6 +3760,7 @@ ActiveRecord::Schema.define(version: 20190703130053) do
add_foreign_key "jira_connect_subscriptions", "jira_connect_installations", name: "fk_f1d617343f", on_delete: :cascade
add_foreign_key "jira_connect_subscriptions", "namespaces", name: "fk_a3c10bcf7d", on_delete: :cascade
add_foreign_key "jira_tracker_data", "services", on_delete: :cascade
+ add_foreign_key "job_logs", "jobs", on_delete: :cascade
add_foreign_key "label_links", "labels", name: "fk_d97dd08678", on_delete: :cascade
add_foreign_key "label_priorities", "labels", on_delete: :cascade
add_foreign_key "label_priorities", "projects", on_delete: :cascade
diff --git a/db/seeds.rb b/db/seeds.rb
index e69de29bb2d..3cad3458733 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -0,0 +1,4 @@
+
+ActiveRecord::Base.connection.execute <<~SQL
+ insert into jobs (scheduled_for) SELECT now() FROM generate_series(1,10000);
+SQL