summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-10-23 11:36:35 +0300
committerShinya Maeda <shinya@gitlab.com>2017-10-23 11:36:35 +0300
commitd0cff7f5855f91b5479f9fdaa39d8d95ec691a9e (patch)
tree892e9ce3d95fdc19d3b258bac2a0cbb4705cf35f /db
parente1d12ba9b988e61afb9317f3a132d6e2caa93923 (diff)
downloadgitlab-ce-d0cff7f5855f91b5479f9fdaa39d8d95ec691a9e.tar.gz
This works
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20171013094327_create_new_clusters_architectures.rb (renamed from db/migrate/20171013094327_create_clusters.rb)18
-rw-r--r--db/migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb.rb84
-rw-r--r--db/schema.rb61
3 files changed, 153 insertions, 10 deletions
diff --git a/db/migrate/20171013094327_create_clusters.rb b/db/migrate/20171013094327_create_new_clusters_architectures.rb
index ad30181f984..35df8cb4a60 100644
--- a/db/migrate/20171013094327_create_clusters.rb
+++ b/db/migrate/20171013094327_create_new_clusters_architectures.rb
@@ -1,4 +1,4 @@
-class CreateGcpClusters < ActiveRecord::Migration
+class CreateNewClustersArchitectures < ActiveRecord::Migration
DOWNTIME = false
def change
@@ -6,6 +6,7 @@ class CreateGcpClusters < ActiveRecord::Migration
t.references :user, foreign_key: { on_delete: :nullify }
t.boolean :enabled, default: true
+ t.string :name, null: false # If manual, read-write. If gcp, read-only.
t.integer :provider_type, null: false
t.integer :platform_type, null: false
@@ -15,14 +16,14 @@ class CreateGcpClusters < ActiveRecord::Migration
end
create_table :cluster_projects do |t|
- t.references :project, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
- t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
+ t.references :project, null: false, index: true, foreign_key: { on_delete: :cascade }
+ t.references :cluster, null: false, index: true, foreign_key: { on_delete: :cascade }
t.datetime_with_timezone :created_at, null: false
t.datetime_with_timezone :updated_at, null: false
end
- create_table :cluster_kubernetes_platforms do |t|
+ create_table :cluster_platforms_kubernetes do |t|
t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
t.string :api_url
@@ -41,16 +42,15 @@ class CreateGcpClusters < ActiveRecord::Migration
t.datetime_with_timezone :updated_at, null: false
end
- create_table :cluster_gcp_providers do |t|
+ create_table :cluster_providers_gcp do |t|
t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
t.integer :status
t.text :status_reason
- t.string :project_id, null: false
- t.string :cluster_zone, null: false
- t.string :cluster_name, null: false
- t.integer :cluster_size, null: false
+ t.string :gcp_project_id, null: false
+ t.string :zone, null: false
+ t.integer :num_nodes, null: false
t.string :machine_type
t.string :operation_id
diff --git a/db/migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb.rb b/db/migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb.rb
new file mode 100644
index 00000000000..5510b036d24
--- /dev/null
+++ b/db/migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb.rb
@@ -0,0 +1,84 @@
+class MigrateGcpClustersToNewClustersArchitectures < ActiveRecord::Migration
+ DOWNTIME = false
+
+ def up
+ # TODO: Chnage to something reaistic
+ ActiveRecord::Base.connection.select_rows('SELECT * from gcp_clusters;').each do |old_cluster|
+ id = old_cluster[0]
+ project_id = old_cluster[1]
+ user_id = old_cluster[2]
+ service_id = old_cluster[3]
+ status = old_cluster[4]
+ gcp_cluster_size = old_cluster[5]
+ created_at = old_cluster[6]
+ updated_at = old_cluster[7]
+ enabled = old_cluster[8]
+ status_reason = old_cluster[9]
+ project_namespace = old_cluster[10]
+ endpoint = old_cluster[11]
+ ca_cert = old_cluster[12]
+ encrypted_kubernetes_token = old_cluster[13]
+ encrypted_kubernetes_token_iv = old_cluster[14]
+ username = old_cluster[15]
+ encrypted_password = old_cluster[16]
+ encrypted_password_iv = old_cluster[17]
+ gcp_project_id = old_cluster[18]
+ gcp_cluster_zone = old_cluster[19]
+ gcp_cluster_name = old_cluster[20]
+ gcp_machine_type = old_cluster[21]
+ gcp_operation_id = old_cluster[22]
+ encrypted_gcp_token = old_cluster[23]
+ encrypted_gcp_token_iv = old_cluster[24]
+
+ cluster = Clusters::Cluster.create!(
+ user_id: user_id,
+ enabled: enabled,
+ name: gcp_cluster_name,
+ provider_type: :gcp,
+ platform_type: :kubernetes,
+ created_at: created_at,
+ updated_at: updated_at)
+
+ Clusters::Project.create!(
+ cluster: cluster,
+ project_id: project_id,
+ created_at: created_at,
+ updated_at: updated_at)
+
+ Clusters::Platforms::Kubernetes.create!(
+ cluster: cluster,
+ api_url: 'https://' + endpoint,
+ ca_cert: ca_cert,
+ namespace: project_namespace,
+ username: username,
+ encrypted_password: encrypted_password,
+ encrypted_password_iv: encrypted_password_iv,
+ encrypted_token: encrypted_kubernetes_token,
+ encrypted_token_iv: encrypted_kubernetes_token_iv,
+ created_at: created_at,
+ updated_at: updated_at)
+
+ Clusters::Providers::Gcp.create!(
+ cluster: cluster,
+ status: status,
+ status_reason: status_reason,
+ gcp_project_id: gcp_project_id,
+ zone: gcp_cluster_zone,
+ num_nodes: gcp_cluster_size,
+ machine_type: gcp_machine_type,
+ operation_id: gcp_operation_id,
+ endpoint: endpoint,
+ encrypted_access_token: encrypted_gcp_token,
+ encrypted_access_token_iv: encrypted_gcp_token_iv,
+ created_at: created_at,
+ updated_at: updated_at)
+ end
+ end
+
+ def down
+ Clusters::Cluster.delete_all
+ Clusters::Project.delete_all
+ Clusters::Providers::Gcp.delete_all
+ Clusters::Platforms::Kubernetes.delete_all
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c2c04873d4d..65e8a3120a1 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20171012101043) do
+ActiveRecord::Schema.define(version: 20171013104327) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -460,6 +460,60 @@ ActiveRecord::Schema.define(version: 20171012101043) do
add_index "ci_variables", ["project_id", "key", "environment_scope"], name: "index_ci_variables_on_project_id_and_key_and_environment_scope", unique: true, using: :btree
+ create_table "cluster_platforms_kubernetes", force: :cascade do |t|
+ t.integer "cluster_id", null: false
+ t.string "api_url"
+ t.text "ca_cert"
+ t.string "namespace"
+ t.string "username"
+ t.text "encrypted_password"
+ t.string "encrypted_password_iv"
+ t.text "encrypted_token"
+ t.string "encrypted_token_iv"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "cluster_platforms_kubernetes", ["cluster_id"], name: "index_cluster_platforms_kubernetes_on_cluster_id", unique: true, using: :btree
+
+ create_table "cluster_projects", force: :cascade do |t|
+ t.integer "project_id", null: false
+ t.integer "cluster_id", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "cluster_projects", ["cluster_id"], name: "index_cluster_projects_on_cluster_id", using: :btree
+ add_index "cluster_projects", ["project_id"], name: "index_cluster_projects_on_project_id", using: :btree
+
+ create_table "cluster_providers_gcp", force: :cascade do |t|
+ t.integer "cluster_id", null: false
+ t.integer "status"
+ t.text "status_reason"
+ t.string "gcp_project_id", null: false
+ t.string "zone", null: false
+ t.integer "num_nodes", null: false
+ t.string "machine_type"
+ t.string "operation_id"
+ t.string "endpoint"
+ t.text "encrypted_access_token"
+ t.string "encrypted_access_token_iv"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "cluster_providers_gcp", ["cluster_id"], name: "index_cluster_providers_gcp_on_cluster_id", unique: true, using: :btree
+
+ create_table "clusters", force: :cascade do |t|
+ t.integer "user_id"
+ t.boolean "enabled", default: true
+ t.string "name", null: false
+ t.integer "provider_type", null: false
+ t.integer "platform_type", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "container_repositories", force: :cascade do |t|
t.integer "project_id", null: false
t.string "name", null: false
@@ -1808,6 +1862,11 @@ ActiveRecord::Schema.define(version: 20171012101043) do
add_foreign_key "ci_triggers", "projects", name: "fk_e3e63f966e", on_delete: :cascade
add_foreign_key "ci_triggers", "users", column: "owner_id", name: "fk_e8e10d1964", on_delete: :cascade
add_foreign_key "ci_variables", "projects", name: "fk_ada5eb64b3", on_delete: :cascade
+ add_foreign_key "cluster_platforms_kubernetes", "clusters", on_delete: :cascade
+ add_foreign_key "cluster_projects", "clusters", on_delete: :cascade
+ add_foreign_key "cluster_projects", "projects", on_delete: :cascade
+ add_foreign_key "cluster_providers_gcp", "clusters", on_delete: :cascade
+ add_foreign_key "clusters", "users", on_delete: :nullify
add_foreign_key "container_repositories", "projects"
add_foreign_key "deploy_keys_projects", "projects", name: "fk_58a901ca7e", on_delete: :cascade
add_foreign_key "deployments", "projects", name: "fk_b9a3851b82", on_delete: :cascade