diff --git a/src/bosh-director/db/migrations/20110209010747_initial.rb b/src/bosh-director/db/migrations/20110209010747_initial.rb new file mode 100644 index 00000000000..ab3fa46d658 --- /dev/null +++ b/src/bosh-director/db/migrations/20110209010747_initial.rb @@ -0,0 +1,1965 @@ +Sequel.migration do + change do + case adapter_scheme + when :postgres + begin + create_table(:agent_dns_versions) do + primary_key :id, :type=>:Bignum + column :agent_id, "text", :null=>false + column :dns_version, "bigint", :default=>0, :null=>false + + index [:agent_id], :unique=>true + end + + create_table(:blobs) do + primary_key :id + column :blobstore_id, "text", :null=>false + column :sha1, "text", :null=>false + column :created_at, "timestamp without time zone", :null=>false + column :type, "text" + end + + create_table(:cloud_configs) do + primary_key :id + column :properties, "text" + column :created_at, "timestamp without time zone", :null=>false + + index [:created_at] + end + + create_table(:configs) do + primary_key :id + column :name, "text", :null=>false + column :type, "text", :null=>false + column :content, "text", :null=>false + column :created_at, "timestamp without time zone", :null=>false + column :deleted, "boolean", :default=>false + column :team_id, "integer" + end + + create_table(:cpi_configs) do + primary_key :id + column :properties, "text" + column :created_at, "timestamp without time zone", :null=>false + + index [:created_at] + end + + create_table(:delayed_jobs) do + primary_key :id + column :priority, "integer", :default=>0, :null=>false + column :attempts, "integer", :default=>0, :null=>false + column :handler, "text", :null=>false + column :last_error, "text" + column :run_at, "timestamp without time zone" + column :locked_at, "timestamp without time zone" + column :failed_at, "timestamp without time zone" + column :locked_by, "text" + column :queue, "text" + + index [:priority, :run_at] + end + + create_table(:deployments) do + primary_key :id + column :name, "text", :null=>false + column :manifest, "text" + column :manifest_text, "text" + column :has_stale_errand_links, "boolean", :default=>false, :null=>false + column :links_serial_id, "integer", :default=>0 + + index [:name], :unique=>true + end + + create_table(:director_attributes) do + column :value, "text" + column :name, "text", :null=>false + primary_key :id, :keep_order=>true + + index [:name], :unique=>true + end + + create_table(:events) do + primary_key :id, :type=>:Bignum + column :parent_id, "bigint" + column :user, "text", :null=>false + column :timestamp, "timestamp without time zone", :null=>false + column :action, "text", :null=>false + column :object_type, "text", :null=>false + column :object_name, "text" + column :error, "text" + column :task, "text" + column :deployment, "text" + column :instance, "text" + column :context_json, "text" + + index [:timestamp] + end + + create_table(:local_dns_encoded_azs) do + primary_key :id + column :name, "text", :null=>false + + index [:name], :unique=>true + end + + create_table(:local_dns_encoded_networks) do + primary_key :id + column :name, "text", :null=>false + + index [:name], :unique=>true + end + + create_table(:locks) do + primary_key :id + column :expired_at, "timestamp without time zone", :null=>false + column :name, "text", :null=>false + column :uid, "text", :null=>false + column :task_id, "text", :default=>"", :null=>false + + index [:name], :unique=>true + index [:uid], :unique=>true + end + + create_table(:log_bundles) do + primary_key :id + column :blobstore_id, "text", :null=>false + column :timestamp, "timestamp without time zone", :null=>false + + index [:blobstore_id], :unique=>true + index [:timestamp] + end + + create_table(:networks) do + primary_key :id + column :name, "text", :null=>false + column :type, "text", :null=>false + column :created_at, "timestamp without time zone", :null=>false + column :orphaned, "boolean", :default=>false + column :orphaned_at, "timestamp without time zone" + + index [:name], :unique=>true + end + + create_table(:orphan_disks) do + primary_key :id + column :disk_cid, "text", :null=>false + column :size, "integer" + column :availability_zone, "text" + column :deployment_name, "text", :null=>false + column :instance_name, "text", :null=>false + column :cloud_properties_json, "text" + column :created_at, "timestamp without time zone", :null=>false + column :cpi, "text", :default=>"" + + index [:disk_cid], :unique=>true + index [:created_at] + end + + create_table(:orphaned_vms) do + primary_key :id + column :cid, "text", :null=>false + column :availability_zone, "text" + column :cloud_properties, "text" + column :cpi, "text" + column :orphaned_at, "timestamp without time zone", :null=>false + column :stemcell_api_version, "integer" + column :deployment_name, "text" + column :instance_name, "text" + end + + create_table(:releases) do + primary_key :id + column :name, "text", :null=>false + + index [:name], :unique=>true + end + + create_table(:runtime_configs) do + primary_key :id + column :properties, "text" + column :created_at, "timestamp without time zone", :null=>false + column :name, "text", :default=>"", :null=>false + + index [:created_at] + end + + create_table(:stemcell_uploads) do + primary_key :id + column :name, "text" + column :version, "text" + column :cpi, "text" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:stemcells) do + primary_key :id + column :name, "text", :null=>false + column :version, "text", :null=>false + column :cid, "text", :null=>false + column :sha1, "text" + column :operating_system, "text" + column :cpi, "text", :default=>"" + column :api_version, "integer" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:tasks) do + primary_key :id + column :state, "text", :null=>false + column :timestamp, "timestamp without time zone", :null=>false + column :description, "text", :null=>false + column :result, "text" + column :output, "text" + column :checkpoint_time, "timestamp without time zone" + column :type, "text", :null=>false + column :username, "text" + column :deployment_name, "text" + column :started_at, "timestamp without time zone" + column :event_output, "text" + column :result_output, "text" + column :context_id, "character varying(64)", :default=>"", :null=>false + + index [:context_id] + index [:description] + index [:state] + index [:timestamp] + index [:type] + end + + create_table(:teams) do + primary_key :id + column :name, "text", :null=>false + + index [:name],:unique=>true + end + + create_table(:deployment_problems) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id] + column :state, "text", :null=>false + column :resource_id, "integer", :null=>false + column :type, "text", :null=>false + column :data_json, "text", :null=>false + column :created_at, "timestamp without time zone", :null=>false + column :last_seen_at, "timestamp without time zone", :null=>false + column :counter, "integer", :default=>0, :null=>false + + index [:deployment_id, :state, :created_at] + index [:deployment_id, :type, :state] + end + + create_table(:deployment_properties) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id] + column :name, "text", :null=>false + column :value, "text", :null=>false + + index [:deployment_id, :name], :unique=>true + end + + create_table(:deployments_configs) do + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :config_id, :configs, :null=>false, :key=>[:id], :on_delete=>:cascade + + index [:deployment_id, :config_id], :unique=>true + end + + create_table(:deployments_networks) do + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :network_id, :networks, :null=>false, :key=>[:id], :on_delete=>:cascade + + index [:deployment_id, :network_id], :unique=>true + end + + create_table(:deployments_stemcells) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id] + foreign_key :stemcell_id, :stemcells, :null=>false, :key=>[:id] + + index [:deployment_id, :stemcell_id], :unique=>true + end + + create_table(:deployments_teams) do + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :team_id, :teams, :null=>false, :key=>[:id], :on_delete=>:cascade + + index [:deployment_id, :team_id], :unique=>true + end + + create_table(:errand_runs) do + primary_key :id + foreign_key :deployment_id, :deployments, :default=>Sequel::LiteralString.new("'-1'::integer"), :null=>false, :key=>[:id], :on_delete=>:cascade + column :errand_name, "text" + column :successful_state_hash, "character varying(512)" + end + + create_table(:link_consumers) do + primary_key :id + foreign_key :deployment_id, :deployments, :key=>[:id], :on_delete=>:cascade + column :instance_group, "text" + column :name, "text", :null=>false + column :type, "text", :null=>false + column :serial_id, "integer" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_consumers_constraint, :unique=>true + end + + create_table(:link_providers) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + column :instance_group, "text", :null=>false + column :name, "text", :null=>false + column :type, "text", :null=>false + column :serial_id, "integer" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_providers_constraint, :unique=>true + end + + create_table(:local_dns_aliases) do + primary_key :id + foreign_key :deployment_id, :deployments, :key=>[:id], :on_delete=>:cascade + column :domain, "text" + column :health_filter, "text" + column :initial_health_check, "text" + column :group_id, "text" + column :placeholder_type, "text" + end + + create_table(:local_dns_blobs) do + primary_key :id, :type=>:Bignum + foreign_key :blob_id, :blobs, :key=>[:id] + column :version, "bigint" + column :created_at, "timestamp without time zone" + column :records_version, "integer", :default=>0, :null=>false + column :aliases_version, "integer", :default=>0, :null=>false + end + + create_table(:local_dns_encoded_groups) do + primary_key :id + column :name, "text", :null=>false + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + column :type, "text", :default=>"instance-group", :null=>false + + index [:name, :type, :deployment_id], :unique=>true + end + + create_table(:orphan_snapshots) do + primary_key :id + foreign_key :orphan_disk_id, :orphan_disks, :null=>false, :key=>[:id] + column :snapshot_cid, "text", :null=>false + column :clean, "boolean", :default=>false + column :created_at, "timestamp without time zone", :null=>false + column :snapshot_created_at, "timestamp without time zone" + + index [:created_at] + index [:snapshot_cid], :unique=>true + end + + create_table(:packages) do + primary_key :id + column :name, "text", :null=>false + column :version, "text", :null=>false + column :blobstore_id, "text" + column :sha1, "text" + column :dependency_set_json, "text", :null=>false + foreign_key :release_id, :releases, :null=>false, :key=>[:id] + column :fingerprint, "text" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:release_versions) do + primary_key :id + column :version, "text", :null=>false + foreign_key :release_id, :releases, :null=>false, :key=>[:id] + column :commit_hash, "text", :default=>"unknown" + column :uncommitted_changes, "boolean", :default=>false + column :update_completed, "boolean", :default=>false, :null=>false + end + + create_table(:subnets) do + primary_key :id + column :cid, "text", :null=>false + column :name, "text", :null=>false + column :range, "text" + column :gateway, "text" + column :reserved, "text" + column :cloud_properties, "text" + column :cpi, "text", :default=>"" + foreign_key :network_id, :networks, :null=>false, :key=>[:id], :on_delete=>:cascade + end + + create_table(:tasks_teams) do + foreign_key :task_id, :tasks, :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :team_id, :teams, :null=>false, :key=>[:id], :on_delete=>:cascade + + index [:task_id, :team_id], :unique=>true + end + + create_table(:templates) do + primary_key :id + column :name, "text", :null=>false + column :version, "text", :null=>false + column :blobstore_id, "text", :null=>false + column :sha1, "text", :null=>false + column :package_names_json, "text", :null=>false + foreign_key :release_id, :releases, :null=>false, :key=>[:id] + column :fingerprint, "text" + column :spec_json, "text" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:variable_sets) do + primary_key :id, :type=>:Bignum + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id], :on_delete=>:cascade + column :created_at, "timestamp without time zone", :null=>false + column :deployed_successfully, "boolean", :default=>false + column :writable, "boolean", :default=>false + + index [:created_at] + end + + create_table(:compiled_packages) do + primary_key :id + column :blobstore_id, "text", :null=>false + column :sha1, "text", :null=>false + column :dependency_key, "text", :null=>false + column :build, "integer", :null=>false + foreign_key :package_id, :packages, :null=>false, :key=>[:id] + column :dependency_key_sha1, "text", :null=>false + column :stemcell_os, "text" + column :stemcell_version, "text" + + index [:package_id, :stemcell_os, :stemcell_version, :build], :name=>:package_stemcell_build_idx, :unique=>true + index [:package_id, :stemcell_os, :stemcell_version, :dependency_key_sha1], :name=>:package_stemcell_dependency_idx, :unique=>true + end + + create_table(:deployments_release_versions) do + primary_key :id + foreign_key :release_version_id, :release_versions, :null=>false, :key=>[:id] + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id] + + index [:release_version_id, :deployment_id], :unique=>true + end + + create_table(:instances) do + primary_key :id + column :job, "text", :null=>false + column :index, "integer", :null=>false + foreign_key :deployment_id, :deployments, :null=>false, :key=>[:id] + column :state, "text", :null=>false + column :uuid, "text" + column :availability_zone, "text" + column :cloud_properties, "text" + column :compilation, "boolean", :default=>false + column :bootstrap, "boolean", :default=>false + column :dns_records, "text" + column :spec_json, "text" + column :vm_cid_bak, "text" + column :agent_id_bak, "text" + column :trusted_certs_sha1_bak, "text", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :update_completed, "boolean", :default=>false + column :ignore, "boolean", :default=>false + foreign_key :variable_set_id, :variable_sets, :type=>"bigint", :null=>false, :key=>[:id] + + index [:agent_id_bak], :unique=>true + index [:uuid], :unique=>true + index [:vm_cid_bak], :unique=>true + end + + create_table(:link_consumer_intents) do + primary_key :id + foreign_key :link_consumer_id, :link_consumers, :key=>[:id], :on_delete=>:cascade + column :original_name, "text", :null=>false + column :type, "text", :null=>false + column :name, "text" + column :optional, "boolean", :default=>false, :null=>false + column :blocked, "boolean", :default=>false, :null=>false + column :metadata, "text" + column :serial_id, "integer" + + index [:link_consumer_id, :original_name], :name=>:link_consumer_intents_constraint, :unique=>true + end + + create_table(:link_provider_intents) do + primary_key :id + foreign_key :link_provider_id, :link_providers, :key=>[:id], :on_delete=>:cascade + column :original_name, "text", :null=>false + column :type, "text", :null=>false + column :name, "text" + column :content, "text" + column :shared, "boolean", :default=>false, :null=>false + column :consumable, "boolean", :default=>true, :null=>false + column :metadata, "text" + column :serial_id, "integer" + + index [:link_provider_id, :original_name], :name=>:link_provider_intents_constraint, :unique=>true + end + + create_table(:packages_release_versions) do + primary_key :id + foreign_key :package_id, :packages, :null=>false, :key=>[:id] + foreign_key :release_version_id, :release_versions, :null=>false, :key=>[:id] + + index [:package_id, :release_version_id], :unique=>true + end + + create_table(:release_versions_templates) do + primary_key :id + foreign_key :release_version_id, :release_versions, :null=>false, :key=>[:id] + foreign_key :template_id, :templates, :null=>false, :key=>[:id] + + index [:release_version_id, :template_id], :unique=>true + end + + create_table(:variables) do + primary_key :id, :type=>:Bignum + column :variable_id, "text", :null=>false + column :variable_name, "text", :null=>false + foreign_key :variable_set_id, :variable_sets, :type=>"bigint", :null=>false, :key=>[:id], :on_delete=>:cascade + column :is_local, "boolean", :default=>true + column :provider_deployment, "text", :default=>"" + + index [:variable_set_id, :variable_name, :provider_deployment], :name=>:variable_set_name_provider_idx, :unique=>true + end + + create_table(:instances_templates) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false, :key=>[:id] + foreign_key :template_id, :templates, :null=>false, :key=>[:id] + + index [:instance_id, :template_id], :unique=>true + end + + create_table(:links) do + primary_key :id + foreign_key :link_provider_intent_id, :link_provider_intents, :key=>[:id], :on_delete=>:set_null + foreign_key :link_consumer_intent_id, :link_consumer_intents, :null=>false, :key=>[:id], :on_delete=>:cascade + column :name, "text", :null=>false + column :link_content, "text" + column :created_at, "timestamp without time zone" + end + + create_table(:local_dns_records) do + primary_key :id, :type=>:Bignum + column :ip, "text", :null=>false + column :az, "text" + column :instance_group, "text" + column :network, "text" + column :deployment, "text" + foreign_key :instance_id, :instances, :key=>[:id] + column :agent_id, "text" + column :domain, "text" + column :links_json, "text" + end + + create_table(:persistent_disks) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false, :key=>[:id] + column :disk_cid, "text", :null=>false + column :size, "integer" + column :active, "boolean", :default=>false + column :cloud_properties_json, "text" + column :name, "text", :default=>"" + column :cpi, "text", :default=>"" + + index [:disk_cid], :unique=>true + end + + create_table(:rendered_templates_archives) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false, :key=>[:id] + column :blobstore_id, "text", :null=>false + column :sha1, "text", :null=>false + column :content_sha1, "text", :null=>false + column :created_at, "timestamp without time zone", :null=>false + + index [:created_at] + end + + create_table(:vms) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false, :key=>[:id] + column :agent_id, "text" + column :cid, "text" + column :trusted_certs_sha1, "text", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :active, "boolean", :default=>false + column :cpi, "text", :default=>"" + column :created_at, "timestamp without time zone" + column :network_spec_json, "text" + column :stemcell_api_version, "integer" + column :stemcell_name, "text" + column :stemcell_version, "text" + column :env_json, "text" + column :cloud_properties_json, "text" + + index [:agent_id], :unique=>true + index [:cid], :unique=>true + end + + create_table(:instances_links) do + primary_key :id + foreign_key :link_id, :links, :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :instance_id, :instances, :null=>false, :key=>[:id], :on_delete=>:cascade + column :serial_id, "integer" + + index [:link_id, :instance_id], :unique=>true + end + + create_table(:ip_addresses) do + primary_key :id + column :network_name, "text" + column :static, "boolean" + foreign_key :instance_id, :instances, :key=>[:id] + column :created_at, "timestamp without time zone" + column :task_id, "text" + column :address_str, "text", :null=>false + foreign_key :vm_id, :vms, :key=>[:id] + column :orphaned_vm_id, "integer" + + index [:address_str], :unique=>true + end + + create_table(:snapshots) do + primary_key :id + foreign_key :persistent_disk_id, :persistent_disks, :null=>false, :key=>[:id] + column :clean, "boolean", :default=>false + column :created_at, "timestamp without time zone", :null=>false + column :snapshot_cid, "text", :null=>false + + index [:snapshot_cid], :unique=>true + end + end + + when :mysql2 + begin + create_table(:agent_dns_versions) do + primary_key :id, :type=>:Bignum + column :agent_id, "varchar(255)", :null=>false + column :dns_version, "bigint", :default=>0, :null=>false + + index [:agent_id], :unique=>true + end + + create_table(:blobs) do + primary_key :id, :type=>"int" + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(512)", :null=>false + column :created_at, "datetime", :null=>false + column :type, "varchar(255)" + end + + create_table(:cloud_configs) do + primary_key :id, :type=>"int" + column :properties, "longtext" + column :created_at, "datetime", :null=>false + + index [:created_at] + end + + create_table(:configs) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :content, "longtext", :null=>false + column :created_at, "datetime", :null=>false + column :deleted, "tinyint(1)", :default=>false + column :team_id, "int" + end + + create_table(:cpi_configs) do + primary_key :id, :type=>"int" + column :properties, "longtext" + column :created_at, "datetime", :null=>false + + index [:created_at] + end + + create_table(:delayed_jobs) do + primary_key :id, :type=>"int" + column :priority, "int", :default=>0, :null=>false + column :attempts, "int", :default=>0, :null=>false + column :handler, "longtext", :null=>false + column :last_error, "longtext" + column :run_at, "datetime" + column :locked_at, "datetime" + column :failed_at, "datetime" + column :locked_by, "varchar(255)" + column :queue, "varchar(255)" + + index [:priority, :run_at] + end + + create_table(:deployments) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :manifest, "longtext" + column :manifest_text, "longtext" + column :has_stale_errand_links, "tinyint(1)", :default=>false, :null=>false + column :links_serial_id, "int", :default=>0 + + index [:name], :unique=>true + end + + create_table(:director_attributes) do + column :value, "longtext" + column :name, "varchar(255)", :null=>false + primary_key :id, :type=>"int", :keep_order=>true + + index [:name], :unique=>true + end + + create_table(:events) do + primary_key :id, :type=>:Bignum + column :parent_id, "bigint" + column :user, "varchar(255)", :null=>false + column :timestamp, "datetime", :null=>false + column :action, "varchar(255)", :null=>false + column :object_type, "varchar(255)", :null=>false + column :object_name, "varchar(255)" + column :error, "longtext" + column :task, "varchar(255)" + column :deployment, "varchar(255)" + column :instance, "varchar(255)" + column :context_json, "longtext" + + index [:timestamp] + end + + create_table(:local_dns_encoded_azs) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:local_dns_encoded_networks) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:locks) do + primary_key :id, :type=>"int" + column :expired_at, "datetime", :null=>false + column :name, "varchar(255)", :null=>false + column :uid, "varchar(255)", :null=>false + column :task_id, "varchar(255)", :default=>"", :null=>false + + index [:name], :unique=>true + index [:uid], :unique=>true + end + + create_table(:log_bundles) do + primary_key :id, :type=>"int" + column :blobstore_id, "varchar(255)", :null=>false + column :timestamp, "datetime", :null=>false + + index [:blobstore_id], :unique=>true + index [:timestamp] + end + + create_table(:networks) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :created_at, "datetime", :null=>false + column :orphaned, "tinyint(1)", :default=>false + column :orphaned_at, "datetime" + + index [:name], :unique=>true + end + + create_table(:orphan_disks) do + primary_key :id, :type=>"int" + column :disk_cid, "varchar(255)", :null=>false + column :size, "int" + column :availability_zone, "varchar(255)" + column :deployment_name, "varchar(255)", :null=>false + column :instance_name, "varchar(255)", :null=>false + column :cloud_properties_json, "longtext" + column :created_at, "datetime", :null=>false + column :cpi, "varchar(255)", :default=>"" + + index [:disk_cid], :unique=>true + index [:created_at] + end + + create_table(:orphaned_vms) do + primary_key :id, :type=>"int" + column :cid, "varchar(255)", :null=>false + column :availability_zone, "varchar(255)" + column :cloud_properties, "longtext" + column :cpi, "varchar(255)" + column :orphaned_at, "datetime", :null=>false + column :stemcell_api_version, "int" + column :deployment_name, "varchar(255)" + column :instance_name, "varchar(255)" + end + + create_table(:releases) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:runtime_configs) do + primary_key :id, :type=>"int" + column :properties, "longtext" + column :created_at, "datetime", :null=>false + column :name, "varchar(255)", :default=>"", :null=>false + + index [:created_at] + end + + create_table(:stemcell_uploads) do + primary_key :id, :type=>"int" + column :name, "varchar(255)" + column :version, "varchar(255)" + column :cpi, "varchar(255)" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:stemcells) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :cid, "varchar(255)", :null=>false + column :sha1, "varchar(512)" + column :operating_system, "varchar(255)" + column :cpi, "varchar(255)", :default=>"" + column :api_version, "int" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:tasks) do + primary_key :id, :type=>"int" + column :state, "varchar(255)", :null=>false + column :timestamp, "datetime", :null=>false + column :description, "varchar(255)", :null=>false + column :result, "longtext" + column :output, "varchar(255)" + column :checkpoint_time, "datetime" + column :type, "varchar(255)", :null=>false + column :username, "varchar(255)" + column :deployment_name, "varchar(255)" + column :started_at, "datetime" + column :event_output, "longtext" + column :result_output, "longtext" + column :context_id, "varchar(64)", :default=>"", :null=>false + + index [:context_id] + index [:description] + index [:state] + index [:timestamp] + index [:type] + end + + create_table(:teams) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:deployment_problems) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + column :state, "varchar(255)", :null=>false + column :resource_id, "int", :null=>false + column :type, "varchar(255)", :null=>false + column :data_json, "longtext", :null=>false + column :created_at, "datetime", :null=>false + column :last_seen_at, "datetime", :null=>false + column :counter, "int", :default=>0, :null=>false + + index [:deployment_id, :state, :created_at] + index [:deployment_id, :type, :state] + end + + create_table(:deployment_properties) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + column :name, "varchar(255)", :null=>false + column :value, "longtext", :null=>false + + index [:deployment_id, :name], :unique=>true + end + + create_table(:deployments_configs) do + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :config_id, :configs, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + + primary_key [:deployment_id, :config_id] + + index [:config_id] + index [:deployment_id, :config_id], :unique=>true + end + + create_table(:deployments_networks) do + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :network_id, :networks, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + + primary_key [:deployment_id, :network_id] + + index [:deployment_id, :network_id], :unique=>true + index [:network_id] + end + + create_table(:deployments_stemcells) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + foreign_key :stemcell_id, :stemcells, :type=>"int", :null=>false, :key=>[:id] + + index [:deployment_id, :stemcell_id], :unique=>true + index [:stemcell_id] + end + + create_table(:deployments_teams) do + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :team_id, :teams, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + + primary_key [:deployment_id, :team_id] + + index [:deployment_id, :team_id], :unique=>true + index [:team_id] + end + + create_table(:errand_runs) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :default=>-1, :type=>"int", :null=>false, :key=>[:id] + column :errand_name, "longtext" + column :successful_state_hash, "varchar(512)" + + index [:deployment_id] + end + + create_table(:link_consumers) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :key=>[:id], :on_delete=>:cascade + column :instance_group, "varchar(255)" + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :serial_id, "int" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_consumers_constraint, :unique=>true + end + + create_table(:link_providers) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + column :instance_group, "varchar(255)", :null=>false + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :serial_id, "int" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_providers_constraint, :unique=>true + end + + create_table(:local_dns_aliases) do + primary_key :id, :type=>"int" + foreign_key :deployment_id, :deployments, :type=>"int", :key=>[:id], :on_delete=>:cascade + column :domain, "varchar(255)" + column :health_filter, "varchar(255)" + column :initial_health_check, "varchar(255)" + column :group_id, "varchar(255)" + column :placeholder_type, "varchar(255)" + + index [:deployment_id] + end + + create_table(:local_dns_blobs) do + primary_key :id, :type=>:Bignum + foreign_key :blob_id, :blobs, :type=>"int", :key=>[:id] + column :version, "bigint" + column :created_at, "datetime" + column :records_version, "int", :default=>0, :null=>false + column :aliases_version, "int", :default=>0, :null=>false + end + + create_table(:local_dns_encoded_groups) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + column :type, "varchar(255)", :default=>"instance-group", :null=>false + + index [:deployment_id] + index [:name, :type, :deployment_id], :unique=>true + end + + create_table(:orphan_snapshots) do + primary_key :id, :type=>"int" + foreign_key :orphan_disk_id, :orphan_disks, :type=>"int", :null=>false, :key=>[:id] + column :snapshot_cid, "varchar(255)", :null=>false + column :clean, "tinyint(1)", :default=>false + column :created_at, "datetime", :null=>false + column :snapshot_created_at, "datetime" + + index [:created_at] + index [:orphan_disk_id] + index [:snapshot_cid], :unique=>true + end + + create_table(:packages) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :blobstore_id, "varchar(255)" + column :sha1, "varchar(512)" + column :dependency_set_json, "longtext", :null=>false + foreign_key :release_id, :releases, :type=>"int", :null=>false, :key=>[:id] + column :fingerprint, "varchar(255)" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:release_versions) do + primary_key :id, :type=>"int" + column :version, "varchar(255)", :null=>false + foreign_key :release_id, :releases, :type=>"int", :null=>false, :key=>[:id] + column :commit_hash, "varchar(255)", :default=>"unknown" + column :uncommitted_changes, "tinyint(1)", :default=>false + column :update_completed, "tinyint(1)", :default=>false, :null=>false + + index [:release_id] + end + + create_table(:subnets) do + primary_key :id, :type=>"int" + column :cid, "varchar(255)", :null=>false + column :name, "varchar(255)", :null=>false + column :range, "varchar(255)" + column :gateway, "varchar(255)" + column :reserved, "varchar(255)" + column :cloud_properties, "varchar(255)" + column :cpi, "varchar(255)", :default=>"" + foreign_key :network_id, :networks, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + + index [:network_id] + end + + create_table(:tasks_teams) do + foreign_key :task_id, :tasks, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :team_id, :teams, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + + primary_key [:task_id, :team_id] + + index [:task_id, :team_id], :unique=>true + index [:team_id] + end + + create_table(:templates) do + primary_key :id, :type=>"int" + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(512)", :null=>false + column :package_names_json, "longtext", :null=>false + foreign_key :release_id, :releases, :type=>"int", :null=>false, :key=>[:id] + column :fingerprint, "varchar(255)" + column :spec_json, "longtext" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:variable_sets) do + primary_key :id, :type=>:Bignum + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + column :created_at, "datetime", :null=>false + column :deployed_successfully, "tinyint(1)", :default=>false + column :writable, "tinyint(1)", :default=>false + + index [:created_at] + index [:deployment_id] + end + + create_table(:compiled_packages) do + primary_key :id, :type=>"int" + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(512)", :null=>false + column :dependency_key, "longtext", :null=>false + column :build, "int", :null=>false + foreign_key :package_id, :packages, :type=>"int", :null=>false, :key=>[:id] + column :dependency_key_sha1, "varchar(255)", :null=>false + column :stemcell_os, "varchar(255)" + column :stemcell_version, "varchar(255)" + + index [:package_id, :stemcell_os, :stemcell_version, :build], :name=>:package_stemcell_build_idx, :unique=>true + index [:package_id, :stemcell_os, :stemcell_version, :dependency_key_sha1], :name=>:package_stemcell_dependency_idx, :unique=>true + end + + create_table(:deployments_release_versions) do + primary_key :id, :type=>"int" + foreign_key :release_version_id, :release_versions, :type=>"int", :null=>false, :key=>[:id] + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + + index [:deployment_id] + index [:release_version_id, :deployment_id], :name=>:release_version_id, :unique=>true + end + + create_table(:instances) do + primary_key :id, :type=>"int" + column :job, "varchar(255)", :null=>false + column :index, "int", :null=>false + foreign_key :deployment_id, :deployments, :type=>"int", :null=>false, :key=>[:id] + column :state, "varchar(255)", :null=>false + column :uuid, "varchar(255)" + column :availability_zone, "varchar(255)" + column :cloud_properties, "longtext" + column :compilation, "tinyint(1)", :default=>false + column :bootstrap, "tinyint(1)", :default=>false + column :dns_records, "longtext" + column :spec_json, "longtext" + column :vm_cid_bak, "varchar(255)" + column :agent_id_bak, "varchar(255)" + column :trusted_certs_sha1_bak, "varchar(255)", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :update_completed, "tinyint(1)", :default=>false + column :ignore, "tinyint(1)", :default=>false + foreign_key :variable_set_id, :variable_sets, :type=>"bigint", :null=>false, :key=>[:id] + + index [:agent_id_bak], :unique=>true + index [:deployment_id] + index [:uuid], :unique=>true + index [:variable_set_id] + index [:vm_cid_bak], :unique=>true + end + + create_table(:link_consumer_intents) do + primary_key :id, :type=>"int" + foreign_key :link_consumer_id, :link_consumers, :type=>"int", :key=>[:id], :on_delete=>:cascade + column :original_name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :name, "varchar(255)" + column :optional, "tinyint(1)", :default=>false, :null=>false + column :blocked, "tinyint(1)", :default=>false, :null=>false + column :metadata, "longtext" + column :serial_id, "int" + + index [:link_consumer_id, :original_name], :name=>:link_consumer_intents_constraint, :unique=>true + end + + create_table(:link_provider_intents) do + primary_key :id, :type=>"int" + foreign_key :link_provider_id, :link_providers, :type=>"int", :key=>[:id], :on_delete=>:cascade + column :original_name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :name, "varchar(255)" + column :content, "longtext" + column :shared, "tinyint(1)", :default=>false, :null=>false + column :consumable, "tinyint(1)", :default=>true, :null=>false + column :metadata, "longtext" + column :serial_id, "int" + + index [:link_provider_id, :original_name], :name=>:link_provider_intents_constraint, :unique=>true + end + + create_table(:packages_release_versions) do + primary_key :id, :type=>"int" + foreign_key :package_id, :packages, :type=>"int", :null=>false, :key=>[:id] + foreign_key :release_version_id, :release_versions, :type=>"int", :null=>false, :key=>[:id] + + index [:package_id, :release_version_id], :unique=>true + index [:release_version_id] + end + + create_table(:release_versions_templates) do + primary_key :id, :type=>"int" + foreign_key :release_version_id, :release_versions, :type=>"int", :null=>false, :key=>[:id] + foreign_key :template_id, :templates, :type=>"int", :null=>false, :key=>[:id] + + index [:release_version_id, :template_id], :unique=>true + index [:template_id] + end + + create_table(:variables) do + primary_key :id, :type=>:Bignum + column :variable_id, "varchar(255)", :null=>false + column :variable_name, "varchar(255)", :null=>false + foreign_key :variable_set_id, :variable_sets, :type=>"bigint", :null=>false, :key=>[:id], :on_delete=>:cascade + column :is_local, "tinyint(1)", :default=>true + column :provider_deployment, "varchar(255)", :default=>"" + + index [:variable_set_id, :variable_name, :provider_deployment], :name=>:variable_set_name_provider_idx, :unique=>true + end + + create_table(:instances_templates) do + primary_key :id, :type=>"int" + foreign_key :instance_id, :instances, :type=>"int", :null=>false, :key=>[:id] + foreign_key :template_id, :templates, :type=>"int", :null=>false, :key=>[:id] + + index [:instance_id, :template_id], :unique=>true + index [:template_id] + end + + create_table(:links) do + primary_key :id, :type=>"int" + foreign_key :link_provider_intent_id, :link_provider_intents, :type=>"int", :key=>[:id], :on_delete=>:set_null + foreign_key :link_consumer_intent_id, :link_consumer_intents, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + column :name, "varchar(255)", :null=>false + column :link_content, "longtext" + column :created_at, "datetime" + + index [:link_consumer_intent_id] + index [:link_provider_intent_id] + end + + create_table(:local_dns_records) do + primary_key :id, :type=>:Bignum + column :ip, "varchar(255)", :null=>false + column :az, "varchar(255)" + column :instance_group, "varchar(255)" + column :network, "varchar(255)" + column :deployment, "varchar(255)" + foreign_key :instance_id, :instances, :type=>"int", :key=>[:id] + column :agent_id, "varchar(255)" + column :domain, "varchar(255)" + column :links_json, "longtext" + + index [:instance_id] + end + + create_table(:persistent_disks) do + primary_key :id, :type=>"int" + foreign_key :instance_id, :instances, :type=>"int", :null=>false, :key=>[:id] + column :disk_cid, "varchar(255)", :null=>false + column :size, "int" + column :active, "tinyint(1)", :default=>false + column :cloud_properties_json, "longtext" + column :name, "varchar(255)", :default=>"" + column :cpi, "varchar(255)", :default=>"" + + index [:disk_cid], :unique=>true + index [:instance_id] + end + + create_table(:rendered_templates_archives) do + primary_key :id, :type=>"int" + foreign_key :instance_id, :instances, :type=>"int", :null=>false, :key=>[:id] + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(255)", :null=>false + column :content_sha1, "varchar(255)", :null=>false + column :created_at, "datetime", :null=>false + + index [:created_at] + index [:instance_id] + end + + create_table(:vms) do + primary_key :id, :type=>"int" + foreign_key :instance_id, :instances, :type=>"int", :null=>false, :key=>[:id] + column :agent_id, "varchar(255)" + column :cid, "varchar(255)" + column :trusted_certs_sha1, "varchar(255)", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :active, "tinyint(1)", :default=>false + column :cpi, "varchar(255)", :default=>"" + column :created_at, "datetime" + column :network_spec_json, "longtext" + column :stemcell_api_version, "int" + column :stemcell_name, "varchar(255)" + column :stemcell_version, "varchar(255)" + column :env_json, "longtext" + column :cloud_properties_json, "longtext" + + index [:agent_id], :unique=>true + index [:cid], :unique=>true + index [:instance_id] + end + + create_table(:instances_links) do + primary_key :id, :type=>"int" + foreign_key :link_id, :links, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + foreign_key :instance_id, :instances, :type=>"int", :null=>false, :key=>[:id], :on_delete=>:cascade + column :serial_id, "int" + + index [:instance_id] + index [:link_id, :instance_id], :unique=>true + end + + create_table(:ip_addresses) do + primary_key :id, :type=>"int" + column :network_name, "varchar(255)" + column :static, "tinyint(1)" + foreign_key :instance_id, :instances, :type=>"int", :key=>[:id] + column :created_at, "datetime" + column :task_id, "varchar(255)" + column :address_str, "varchar(255)", :null=>false + foreign_key :vm_id, :vms, :type=>"int", :key=>[:id] + column :orphaned_vm_id, "int" + + index [:address_str], :unique=>true + index [:instance_id] + index [:vm_id] + end + + create_table(:snapshots) do + primary_key :id, :type=>"int" + foreign_key :persistent_disk_id, :persistent_disks, :type=>"int", :null=>false, :key=>[:id] + column :clean, "tinyint(1)", :default=>false + column :created_at, "datetime", :null=>false + column :snapshot_cid, "varchar(255)", :null=>false + + index [:persistent_disk_id] + index [:snapshot_cid], :unique=>true + end + end + + when :sqlite + begin + create_table(:agent_dns_versions) do + primary_key :id + column :agent_id, "varchar(255)", :null=>false + column :dns_version, "INTEGER", :default=>0, :null=>false + + index [:agent_id], :unique=>true + end + + create_table(:blobs) do + primary_key :id + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(255)", :null=>false + column :created_at, "timestamp", :null=>false + column :type, "varchar(255)" + end + + create_table(:cloud_configs) do + primary_key :id + column :properties, "TEXT" + column :created_at, "timestamp", :null=>false + + index [:created_at] + end + + create_table(:configs) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :content, "TEXT", :null=>false + column :created_at, "timestamp", :null=>false + column :deleted, "boolean", :default=>false + column :team_id, "INTEGER" + end + + create_table(:cpi_configs) do + primary_key :id + column :properties, "TEXT" + column :created_at, "timestamp", :null=>false + + index [:created_at] + end + + create_table(:delayed_jobs) do + primary_key :id + column :priority, "INTEGER", :default=>0, :null=>false + column :attempts, "INTEGER", :default=>0, :null=>false + column :handler, "TEXT", :null=>false + column :last_error, "TEXT" + column :run_at, "timestamp" + column :locked_at, "timestamp" + column :failed_at, "timestamp" + column :locked_by, "varchar(255)" + column :queue, "varchar(255)" + + index [:priority, :run_at] + end + + create_table(:deployments) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :manifest, "TEXT" + column :manifest_text, "TEXT" + column :has_stale_errand_links, "boolean", :default=>false, :null=>false + column :links_serial_id, "INTEGER", :default=>0 + + index [:name], :unique=>true + end + + create_table(:director_attributes) do + column :value, "TEXT" + column :name, "varchar(255)", :null=>false + primary_key :id, :keep_order=>true + + index [:name], :unique=>true + end + + create_table(:events) do + primary_key :id + column :parent_id, "INTEGER" + column :user, "varchar(255)", :null=>false + column :timestamp, "timestamp", :null=>false + column :action, "varchar(255)", :null=>false + column :object_type, "varchar(255)", :null=>false + column :object_name, "varchar(255)" + column :error, "TEXT" + column :task, "varchar(255)" + column :deployment, "varchar(255)" + column :instance, "varchar(255)" + column :context_json, "TEXT" + + index [:timestamp] + end + + create_table(:local_dns_encoded_azs) do + primary_key :id + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:local_dns_encoded_networks) do + primary_key :id + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:locks) do + primary_key :id + column :expired_at, "timestamp", :null=>false + column :name, "varchar(255)", :null=>false + column :uid, "varchar(255)", :null=>false + column :task_id, "varchar(255)", :default=>"", :null=>false + + index [:name], :unique=>true + index [:uid], :unique=>true + end + + create_table(:log_bundles) do + primary_key :id + column :blobstore_id, "varchar(255)", :null=>false + column :timestamp, "timestamp", :null=>false + + index [:blobstore_id], :unique=>true + index [:timestamp] + end + + create_table(:networks) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :created_at, "timestamp", :null=>false + column :orphaned, "Boolean", :default=>false + column :orphaned_at, "timestamp" + + index [:name], :unique=>true + end + + create_table(:orphan_disks) do + primary_key :id + column :disk_cid, "varchar(255)", :null=>false + column :size, "INTEGER" + column :availability_zone, "varchar(255)" + column :deployment_name, "varchar(255)", :null=>false + column :instance_name, "varchar(255)", :null=>false + column :cloud_properties_json, "TEXT" + column :created_at, "timestamp", :null=>false + column :cpi, "varchar(255)", :default=>"" + + index [:disk_cid], :unique=>true + index [:created_at] + end + + create_table(:orphaned_vms) do + primary_key :id + column :cid, "varchar(255)", :null=>false + column :availability_zone, "varchar(255)" + column :cloud_properties, "TEXT" + column :cpi, "varchar(255)" + column :orphaned_at, "timestamp", :null=>false + column :stemcell_api_version, "INTEGER" + column :deployment_name, "varchar(255)" + column :instance_name, "varchar(255)" + end + + create_table(:releases) do + primary_key :id + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:runtime_configs) do + primary_key :id + column :properties, "TEXT" + column :created_at, "timestamp", :null=>false + column :name, "varchar(255)", :default=>"", :null=>false + + index [:created_at] + end + + create_table(:stemcell_uploads) do + primary_key :id + column :name, "varchar(255)" + column :version, "varchar(255)" + column :cpi, "varchar(255)" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:stemcells) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :cid, "varchar(255)", :null=>false + column :sha1, "varchar(255)" + column :operating_system, "varchar(255)" + column :cpi, "varchar(255)", :default=>"" + column :api_version, "INTEGER" + + index [:name, :version, :cpi], :unique=>true + end + + create_table(:tasks) do + primary_key :id + column :state, "varchar(255)", :null=>false + column :timestamp, "timestamp", :null=>false + column :description, "varchar(255)", :null=>false + column :result, "TEXT" + column :output, "varchar(255)" + column :checkpoint_time, "timestamp" + column :type, "varchar(255)", :null=>false + column :username, "varchar(255)" + column :deployment_name, "varchar(255)" + column :started_at, "timestamp" + column :event_output, "TEXT" + column :result_output, "TEXT" + column :context_id, "varchar(64)", :default=>"", :null=>false + + index [:context_id] + index [:description] + index [:state] + index [:timestamp] + index [:type] + end + + create_table(:teams) do + primary_key :id + column :name, "varchar(255)", :null=>false + + index [:name], :unique=>true + end + + create_table(:deployment_problems) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false + column :state, "varchar(255)", :null=>false + column :resource_id, "INTEGER", :null=>false + column :type, "varchar(255)", :null=>false + column :data_json, "TEXT", :null=>false + column :created_at, "timestamp", :null=>false + column :last_seen_at, "timestamp", :null=>false + column :counter, "INTEGER", :default=>0, :null=>false + + index [:deployment_id, :state, :created_at] + index [:deployment_id, :type, :state] + end + + create_table(:deployment_properties) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false + column :name, "varchar(255)", :null=>false + column :value, "TEXT", :null=>false + + index [:deployment_id, :name], :unique=>true + end + + create_table(:deployments_configs) do + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + foreign_key :config_id, :configs, :null=>false, :on_delete=>:cascade + + index [:deployment_id, :config_id], :unique=>true + end + + create_table(:deployments_networks) do + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + foreign_key :network_id, :networks, :null=>false, :on_delete=>:cascade + + index [:deployment_id, :network_id], :unique=>true + end + + create_table(:deployments_stemcells) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false + foreign_key :stemcell_id, :stemcells, :null=>false + + index [:deployment_id, :stemcell_id], :unique=>true + end + + create_table(:deployments_teams) do + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + foreign_key :team_id, :teams, :null=>false, :on_delete=>:cascade + + index [:deployment_id, :team_id], :unique=>true + end + + create_table(:errand_runs) do + primary_key :id + foreign_key :deployment_id, :deployments, :default=>-1, :null=>false, :on_delete=>:cascade + column :errand_name, "TEXT" + column :successful_state_hash, "varchar(512)" + end + + create_table(:link_consumers) do + primary_key :id + foreign_key :deployment_id, :deployments, :on_delete=>:cascade + column :instance_group, "varchar(255)" + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :serial_id, "INTEGER" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_consumers_constraint, :unique=>true + end + + create_table(:link_providers) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + column :instance_group, "varchar(255)", :null=>false + column :name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :serial_id, "INTEGER" + + index [:deployment_id, :instance_group, :name, :type], :name=>:link_providers_constraint, :unique=>true + end + + create_table(:local_dns_aliases) do + primary_key :id + foreign_key :deployment_id, :deployments, :on_delete=>:cascade + column :domain, "varchar(255)" + column :health_filter, "varchar(255)" + column :initial_health_check, "varchar(255)" + column :group_id, "varchar(255)" + column :placeholder_type, "varchar(255)" + end + + create_table(:local_dns_blobs) do + primary_key :id + foreign_key :blob_id, :blobs + column :version, "bigint" + column :created_at, "timestamp" + column :records_version, "INTEGER", :default=>0, :null=>false + column :aliases_version, "INTEGER", :default=>0, :null=>false + end + + create_table(:local_dns_encoded_groups) do + primary_key :id + column :name, "varchar(255)", :null=>false + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + column :type, "varchar(255)", :default=>"instance-group", :null=>false + + index [:name, :type, :deployment_id], :unique=>true + end + + create_table(:orphan_snapshots) do + primary_key :id + foreign_key :orphan_disk_id, :orphan_disks, :null=>false + column :snapshot_cid, "varchar(255)", :null=>false + column :clean, "Boolean", :default=>false + column :created_at, "timestamp", :null=>false + column :snapshot_created_at, "timestamp" + + index [:created_at] + index [:snapshot_cid], :unique=>true + end + + create_table(:packages) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :blobstore_id, "varchar(255)" + column :sha1, "varchar(255)" + column :dependency_set_json, "TEXT", :null=>false + foreign_key :release_id, :releases, :null=>false + column :fingerprint, "varchar(255)" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:release_versions) do + primary_key :id + column :version, "varchar(255)", :null=>false + foreign_key :release_id, :releases, :null=>false + column :commit_hash, "varchar(255)", :default=>"unknown" + column :uncommitted_changes, "boolean", :default=>false + column :update_completed, "boolean", :default=>false, :null=>false + end + + create_table(:subnets) do + primary_key :id + column :cid, "varchar(255)", :null=>false + column :name, "varchar(255)", :null=>false + column :range, "varchar(255)" + column :gateway, "varchar(255)" + column :reserved, "varchar(255)" + column :cloud_properties, "varchar(255)" + column :cpi, "varchar(255)", :default=>"" + foreign_key :network_id, :networks, :null=>false, :on_delete=>:cascade + end + + create_table(:tasks_teams) do + foreign_key :task_id, :tasks, :null=>false, :on_delete=>:cascade + foreign_key :team_id, :teams, :null=>false, :on_delete=>:cascade + + index [:task_id, :team_id], :unique=>true + end + + create_table(:templates) do + primary_key :id + column :name, "varchar(255)", :null=>false + column :version, "varchar(255)", :null=>false + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(255)", :null=>false + column :package_names_json, "TEXT", :null=>false + foreign_key :release_id, :releases, :null=>false + column :fingerprint, "varchar(255)" + column :spec_json, "varchar(255)" + + index [:fingerprint] + index [:release_id, :name, :version], :unique=>true + index [:sha1] + end + + create_table(:variable_sets) do + primary_key :id + foreign_key :deployment_id, :deployments, :null=>false, :on_delete=>:cascade + column :created_at, "timestamp", :null=>false + column :deployed_successfully, "boolean", :default=>false + column :writable, "boolean", :default=>false + + index [:created_at] + end + + create_table(:compiled_packages) do + primary_key :id + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(255)", :null=>false + column :dependency_key, "TEXT", :null=>false + column :build, "INTEGER", :null=>false + foreign_key :package_id, :packages, :null=>false + column :dependency_key_sha1, "varchar(255)", :null=>false + column :stemcell_os, "varchar(255)" + column :stemcell_version, "varchar(255)" + + index [:package_id, :stemcell_os, :stemcell_version, :build], :unique=>true + index [:package_id, :stemcell_os, :stemcell_version, :dependency_key_sha1], :unique=>true + end + + create_table(:deployments_release_versions) do + primary_key :id + foreign_key :release_version_id, :release_versions, :null=>false + foreign_key :deployment_id, :deployments, :null=>false + + index [:release_version_id, :deployment_id], :unique=>true + end + + create_table(:instances) do + primary_key :id + column :job, "varchar(255)", :null=>false + column :index, "INTEGER", :null=>false + foreign_key :deployment_id, :deployments, :null=>false + column :state, "varchar(255)", :null=>false + column :uuid, "varchar(255)" + column :availability_zone, "varchar(255)" + column :cloud_properties, "TEXT" + column :compilation, "boolean", :default=>false + column :bootstrap, "boolean", :default=>false + column :dns_records, "TEXT" + column :spec_json, "TEXT" + column :vm_cid_bak, "varchar(255)" + column :agent_id_bak, "varchar(255)" + column :trusted_certs_sha1_bak, "varchar(255)", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :update_completed, "boolean", :default=>false + column :ignore, "boolean", :default=>false + foreign_key :variable_set_id, :variable_sets, :null=>false + + index [:agent_id_bak], :unique=>true + index [:uuid], :unique=>true + index [:vm_cid_bak], :unique=>true + end + + create_table(:link_consumer_intents) do + primary_key :id + foreign_key :link_consumer_id, :link_consumers, :on_delete=>:cascade + column :original_name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :name, "varchar(255)" + column :optional, "Boolean", :default=>false, :null=>false + column :blocked, "Boolean", :default=>false, :null=>false + column :metadata, "varchar(255)" + column :serial_id, "INTEGER" + + index [:link_consumer_id, :original_name], :name=>:link_consumer_intents_constraint, :unique=>true + end + + create_table(:link_provider_intents) do + primary_key :id + foreign_key :link_provider_id, :link_providers, :on_delete=>:cascade + column :original_name, "varchar(255)", :null=>false + column :type, "varchar(255)", :null=>false + column :name, "varchar(255)" + column :content, "varchar(255)" + column :shared, "Boolean", :default=>false, :null=>false + column :consumable, "Boolean", :default=>true, :null=>false + column :metadata, "varchar(255)" + column :serial_id, "INTEGER" + + index [:link_provider_id, :original_name], :name=>:link_provider_intents_constraint, :unique=>true + end + + create_table(:packages_release_versions) do + primary_key :id + foreign_key :package_id, :packages, :null=>false + foreign_key :release_version_id, :release_versions, :null=>false + + index [:package_id, :release_version_id], :unique=>true + end + + create_table(:release_versions_templates) do + primary_key :id + foreign_key :release_version_id, :release_versions, :null=>false + foreign_key :template_id, :templates, :null=>false + + index [:release_version_id, :template_id], :unique=>true + end + + create_table(:variables) do + primary_key :id + column :variable_id, "varchar(255)", :null=>false + column :variable_name, "varchar(255)", :null=>false + foreign_key :variable_set_id, :variable_sets, :null=>false, :on_delete=>:cascade + column :is_local, "boolean", :default=>true + column :provider_deployment, "varchar(255)", :default=>"" + + index [:variable_set_id, :variable_name, :provider_deployment], :name=>:variable_set_name_provider_idx, :unique=>true + end + + create_table(:instances_templates) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false + foreign_key :template_id, :templates, :null=>false + + index [:instance_id, :template_id], :unique=>true + end + + create_table(:links) do + primary_key :id + foreign_key :link_provider_intent_id, :link_provider_intents, :on_delete=>:set_null + foreign_key :link_consumer_intent_id, :link_consumer_intents, :null=>false, :on_delete=>:cascade + column :name, "varchar(255)", :null=>false + column :link_content, "varchar(255)" + column :created_at, "timestamp" + end + + create_table(:local_dns_records) do + primary_key :id + column :ip, "varchar(255)", :null=>false + column :az, "varchar(255)" + column :instance_group, "varchar(255)" + column :network, "varchar(255)" + column :deployment, "varchar(255)" + foreign_key :instance_id, :instances + column :agent_id, "varchar(255)" + column :domain, "varchar(255)" + column :links_json, "TEXT" + end + + create_table(:persistent_disks) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false + column :disk_cid, "varchar(255)", :null=>false + column :size, "INTEGER" + column :active, "Boolean", :default=>false + column :cloud_properties_json, "TEXT" + column :name, "varchar(255)", :default=>"" + column :cpi, "varchar(255)", :default=>"" + + index [:disk_cid], :unique=>true + end + + create_table(:rendered_templates_archives) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false + column :blobstore_id, "varchar(255)", :null=>false + column :sha1, "varchar(255)", :null=>false + column :content_sha1, "varchar(255)", :null=>false + column :created_at, "timestamp", :null=>false + + index [:created_at] + end + + create_table(:vms) do + primary_key :id + foreign_key :instance_id, :instances, :null=>false + column :agent_id, "varchar(255)" + column :cid, "varchar(255)" + column :trusted_certs_sha1, "varchar(255)", :default=>"da39a3ee5e6b4b0d3255bfef95601890afd80709" + column :active, "boolean", :default=>false + column :cpi, "varchar(255)", :default=>"" + column :created_at, "timestamp" + column :network_spec_json, "varchar(255)" + column :stemcell_api_version, "INTEGER" + column :stemcell_name, "varchar(255)" + column :stemcell_version, "varchar(255)" + column :env_json, "varchar(255)" + column :cloud_properties_json, "varchar(255)" + + index [:agent_id], :unique=>true + index [:cid], :unique=>true + end + + create_table(:instances_links) do + primary_key :id + foreign_key :link_id, :links, :null=>false, :on_delete=>:cascade + foreign_key :instance_id, :instances, :null=>false, :on_delete=>:cascade + column :serial_id, "INTEGER" + + index [:link_id, :instance_id], :unique=>true + end + + create_table(:ip_addresses) do + primary_key :id + column :network_name, "varchar(255)" + column :static, "Boolean" + foreign_key :instance_id, :instances + column :created_at, "timestamp" + column :task_id, "varchar(255)" + column :address_str, "varchar(255)", :null=>false + foreign_key :vm_id, :vms + column :orphaned_vm_id, "INTEGER" + + index [:address_str], :unique=>true + end + + create_table(:snapshots) do + primary_key :id + foreign_key :persistent_disk_id, :persistent_disks, :null=>false + column :clean, "Boolean", :default=>false + column :created_at, "timestamp", :null=>false + column :snapshot_cid, "varchar(255)", :null=>false + + index [:snapshot_cid], :unique=>true + end + end + + else + raise "Unknown adapter_scheme: #{adapter_scheme}" + + end + end +end diff --git a/src/bosh-director/db/migrations/director/20210902232124_add_blobstore_and_nats_shas_to_vms.rb b/src/bosh-director/db/migrations/20210902232124_add_blobstore_and_nats_shas_to_vms.rb similarity index 100% rename from src/bosh-director/db/migrations/director/20210902232124_add_blobstore_and_nats_shas_to_vms.rb rename to src/bosh-director/db/migrations/20210902232124_add_blobstore_and_nats_shas_to_vms.rb diff --git a/src/bosh-director/db/migrations/director/20230103143246_add_permanent_nats_credentials_to_vms.rb b/src/bosh-director/db/migrations/20230103143246_add_permanent_nats_credentials_to_vms.rb similarity index 100% rename from src/bosh-director/db/migrations/director/20230103143246_add_permanent_nats_credentials_to_vms.rb rename to src/bosh-director/db/migrations/20230103143246_add_permanent_nats_credentials_to_vms.rb diff --git a/src/bosh-director/db/migrations/director/20240319204601_remove_dns_records_from_instances.rb b/src/bosh-director/db/migrations/20240319204601_remove_dns_records_from_instances.rb similarity index 100% rename from src/bosh-director/db/migrations/director/20240319204601_remove_dns_records_from_instances.rb rename to src/bosh-director/db/migrations/20240319204601_remove_dns_records_from_instances.rb diff --git a/src/bosh-director/db/migrations/director/20110209010747_initial.rb b/src/bosh-director/db/migrations/director/20110209010747_initial.rb deleted file mode 100644 index dc0e146d875..00000000000 --- a/src/bosh-director/db/migrations/director/20110209010747_initial.rb +++ /dev/null @@ -1,116 +0,0 @@ -Sequel.migration do - change do - create_table :releases do - primary_key :id - String :name, :null => false, :unique => true - end - - create_table :release_versions do - primary_key :id - String :version, :null => false - foreign_key :release_id, :releases, :null => false - end - - create_table :packages do - primary_key :id - String :name, :null => false - String :version, :null => false - String :blobstore_id, :null => false - String :sha1, :null => false - String :dependency_set_json, :null => false, :text => true - foreign_key :release_id, :releases, :null => false - unique [:release_id, :name, :version] - end - - create_table :templates do - primary_key :id - String :name, :null => false - String :version, :null => false - String :blobstore_id, :null => false - String :sha1, :null => false - String :package_names_json, :null => false, :text => true - foreign_key :release_id, :releases, :null => false - unique [:release_id, :name, :version] - end - - create_table :stemcells do - primary_key :id - String :name, :null => false - String :version, :null => false - String :cid, :null => false - unique [:name, :version] - end - - create_table :compiled_packages do - primary_key :id - String :blobstore_id, :null => false - String :sha1, :null => false - String :dependency_key, :null => false - Integer :build, :unsigned => true, :null => false - foreign_key :package_id, :packages, :null => false - foreign_key :stemcell_id, :stemcells, :null => false - unique [:package_id, :stemcell_id, :dependency_key] - unique [:package_id, :stemcell_id, :build] - end - - create_table :deployments do - primary_key :id - String :name, :null => false, :unique => true - String :manifest, :null => true, :text => true - foreign_key :release_id, :releases, :null => true - end - - create_table :vms do - primary_key :id - String :agent_id, :null => false, :unique => true - String :cid, :null => false - foreign_key :deployment_id, :deployments, :null => false - end - - create_table :instances do - primary_key :id - String :job, :null => false - Integer :index, :unsigned => true, :null => false - String :disk_cid, :unique => true, :null => true - foreign_key :deployment_id, :deployments, :null => false - foreign_key :vm_id, :vms, :unique => true, :null => true - end - - create_table :tasks do - primary_key :id - String :state, :index => true, :null => false - Time :timestamp, :index => true, :null => false - String :description, :null => false - String :result, :text => true, :null => true - String :output, :null => true - end - - create_table :users do - primary_key :id - String :username, :unique => true, :null => false - String :password, :null => false - end - - create_table :packages_release_versions do - primary_key :id - foreign_key :package_id, :packages, :null => false - foreign_key :release_version_id, :release_versions, :null => false - unique [:package_id, :release_version_id] - end - - create_table :release_versions_templates do - primary_key :id - foreign_key :release_version_id, :release_versions, :null => false - foreign_key :template_id, :templates, :null => false - unique [:release_version_id, :template_id] - end - - create_table :deployments_stemcells do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false - foreign_key :stemcell_id, :stemcells, :null => false - unique [:deployment_id, :stemcell_id] - end - - end -end diff --git a/src/bosh-director/db/migrations/director/20110406055800_add_task_user.rb b/src/bosh-director/db/migrations/director/20110406055800_add_task_user.rb deleted file mode 100644 index 6396ea8fd1d..00000000000 --- a/src/bosh-director/db/migrations/director/20110406055800_add_task_user.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_foreign_key :user_id, :users - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20110518225809_remove_cid_constrain.rb b/src/bosh-director/db/migrations/director/20110518225809_remove_cid_constrain.rb deleted file mode 100644 index bd69b0fdfbc..00000000000 --- a/src/bosh-director/db/migrations/director/20110518225809_remove_cid_constrain.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - up do - alter_table(:vms) do - set_column_allow_null :cid, true - end - end - - down do - raise Sequel::Error, "Irreversible migration, vms:cid might contain nulls so we cannot enforce 'not null' constraint" - end -end diff --git a/src/bosh-director/db/migrations/director/20110617211923_add_deployments_release_versions.rb b/src/bosh-director/db/migrations/director/20110617211923_add_deployments_release_versions.rb deleted file mode 100644 index e34216d5fba..00000000000 --- a/src/bosh-director/db/migrations/director/20110617211923_add_deployments_release_versions.rb +++ /dev/null @@ -1,30 +0,0 @@ -Sequel.migration do - up do - create_table(:deployments_release_versions) do - primary_key :id - foreign_key :release_version_id, :release_versions, :null => false - foreign_key :deployment_id, :deployments, :null => false - unique [:release_version_id, :deployment_id] - end - - self[:deployments].each do |deployment| - manifest = YAML.load(deployment[:manifest]) - - unless manifest.is_a?(Hash) && manifest["release"] && manifest["release"]["version"] - raise "Invalid manifest for '#{deployment[:name]}', no version data" - end - - release_version = self[:release_versions].filter(:release_id => deployment[:release_id], :version => manifest["release"]["version"].to_s).first - - if release_version.nil? - raise "Release version #{manifest["release"]["version"]} referenced by '#{deployment[:name]}' manifest not found" - end - - self[:deployments_release_versions].insert(:release_version_id => release_version[:id], :deployment_id => deployment[:id]) - end - end - - down do - drop_table(:deployments_release_versions) - end -end diff --git a/src/bosh-director/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb b/src/bosh-director/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb deleted file mode 100644 index 881195319f2..00000000000 --- a/src/bosh-director/db/migrations/director/20110622212607_add_task_checkpoint_timestamp.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_column(:checkpoint_time, Time) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20110628023039_add_state_to_instances.rb b/src/bosh-director/db/migrations/director/20110628023039_add_state_to_instances.rb deleted file mode 100644 index 8c4bba60e9b..00000000000 --- a/src/bosh-director/db/migrations/director/20110628023039_add_state_to_instances.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - up do - alter_table(:instances) do - add_column(:state, String) - end - - self[:instances].update(:state => "started") - - alter_table(:instances) do - set_column_allow_null :state, false - end - end - - down do - alter_table(:instances) do - drop_column(:state) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20110709012332_add_disk_size_to_instances.rb b/src/bosh-director/db/migrations/director/20110709012332_add_disk_size_to_instances.rb deleted file mode 100644 index e08290ca661..00000000000 --- a/src/bosh-director/db/migrations/director/20110709012332_add_disk_size_to_instances.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :disk_size, Integer - end - end -end diff --git a/src/bosh-director/db/migrations/director/20110906183441_add_log_bundles.rb b/src/bosh-director/db/migrations/director/20110906183441_add_log_bundles.rb deleted file mode 100644 index 98741dbfe89..00000000000 --- a/src/bosh-director/db/migrations/director/20110906183441_add_log_bundles.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - change do - create_table :log_bundles do - primary_key :id - String :blobstore_id, :null => false, :unique => true - Time :timestamp, :null => false, :index => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20110907194830_add_logs_json_to_templates.rb b/src/bosh-director/db/migrations/director/20110907194830_add_logs_json_to_templates.rb deleted file mode 100644 index 63a7d23672e..00000000000 --- a/src/bosh-director/db/migrations/director/20110907194830_add_logs_json_to_templates.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:templates) do - add_column :logs_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20110915205610_add_persistent_disks.rb b/src/bosh-director/db/migrations/director/20110915205610_add_persistent_disks.rb deleted file mode 100644 index d0cc53e38e2..00000000000 --- a/src/bosh-director/db/migrations/director/20110915205610_add_persistent_disks.rb +++ /dev/null @@ -1,49 +0,0 @@ -Sequel.migration do - up do - create_table(:persistent_disks) do - primary_key :id - foreign_key :instance_id, :instances, :null => false - String :disk_cid, :unique => true, :null => false - Integer :size - Boolean :active, :default => false - end - - self[:instances].each do |instance| - next unless instance[:disk_cid] - - new_disk_attrs = { - :disk_cid => instance[:disk_cid], - :size => instance[:disk_size], - :instance_id => instance[:id], - :active => true - } - - self[:persistent_disks].insert(new_disk_attrs) - end - - alter_table(:instances) do - drop_column :disk_cid - drop_column :disk_size - end - end - - down do - alter_table(:instances) do - add_column(:disk_size, Integer, :default => 0) - add_column(:disk_cid, String) - end - - self[:persistent_disks].each do |disk| - next unless disk[:active] - - instance_attrs = { - :disk_cid => disk[:disk_cid], - :disk_size => disk[:size] - } - - self[:instances].filter(:id => disk[:instance_id]).update(instance_attrs) - end - - drop_table(:persistent_disks) - end -end diff --git a/src/bosh-director/db/migrations/director/20111005180929_add_properties.rb b/src/bosh-director/db/migrations/director/20111005180929_add_properties.rb deleted file mode 100644 index 14cc7249a58..00000000000 --- a/src/bosh-director/db/migrations/director/20111005180929_add_properties.rb +++ /dev/null @@ -1,12 +0,0 @@ -Sequel.migration do - change do - create_table :deployment_properties do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false - String :name, :null => false - String :value, :null => false - - unique [ :deployment_id, :name ] - end - end -end diff --git a/src/bosh-director/db/migrations/director/20111110024617_add_deployment_problems.rb b/src/bosh-director/db/migrations/director/20111110024617_add_deployment_problems.rb deleted file mode 100644 index 0cda34c21e3..00000000000 --- a/src/bosh-director/db/migrations/director/20111110024617_add_deployment_problems.rb +++ /dev/null @@ -1,22 +0,0 @@ -Sequel.migration do - change do - create_table :deployment_problems do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false - - String :state, :null => false - - Integer :resource_id, :null => false - String :type, :null => false - String :data_json, :text => true, :null => false - - Time :created_at, :null => false - Time :last_seen_at, :null => false - - Integer :counter, :null => false, :default => 0 - - index [:deployment_id, :type, :state] - index [:deployment_id, :state, :created_at] - end - end -end diff --git a/src/bosh-director/db/migrations/director/20111216214145_recreate_support_for_vms.rb b/src/bosh-director/db/migrations/director/20111216214145_recreate_support_for_vms.rb deleted file mode 100644 index 897797aacdb..00000000000 --- a/src/bosh-director/db/migrations/director/20111216214145_recreate_support_for_vms.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:vms) do - add_column :apply_spec_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20120102084027_add_credentials_to_vms.rb b/src/bosh-director/db/migrations/director/20120102084027_add_credentials_to_vms.rb deleted file mode 100644 index 83005c1e4b5..00000000000 --- a/src/bosh-director/db/migrations/director/20120102084027_add_credentials_to_vms.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:vms) do - add_column :credentials_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb b/src/bosh-director/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb deleted file mode 100644 index e3a267926e6..00000000000 --- a/src/bosh-director/db/migrations/director/20120427235217_allow_multiple_releases_per_deployment.rb +++ /dev/null @@ -1,34 +0,0 @@ -Sequel.migration do - up do - create_table :deployments_releases do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false - foreign_key :release_id, :releases, :null => false - unique [:deployment_id, :release_id] - end - - self[:deployments].each do |deployment| - attrs = { - :release_id => deployment[:release_id], - :deployment_id => deployment[:id] - } - - self[:deployments_releases].insert(attrs) - end - - # Needed for mysql in order to drop column (doesn't work with other adapters) - # newer versions of sequel support drop_foreign_key but the version breaks tests - if [:mysql2, :mysql].include?(adapter_scheme) - run("alter table deployments drop FOREIGN KEY deployments_ibfk_1") - end - - alter_table :deployments do - drop_column :release_id - end - end - - down do - raise Sequel::Error, "Irreversible migration, cannot easily go from " + - "many-to-many to one-to-many" - end -end diff --git a/src/bosh-director/db/migrations/director/20120524175805_add_task_type.rb b/src/bosh-director/db/migrations/director/20120524175805_add_task_type.rb deleted file mode 100644 index c13143679bc..00000000000 --- a/src/bosh-director/db/migrations/director/20120524175805_add_task_type.rb +++ /dev/null @@ -1,42 +0,0 @@ -Sequel.migration do - up do - alter_table :tasks do - add_column :type, String - add_index :description - end - - self[:tasks].filter(description: 'create deployment'). - update(:type => 'update_deployment') - self[:tasks].grep(:description, 'delete deployment:%'). - update(:type => 'delete_deployment') - self[:tasks].filter(:description => 'fetch logs'). - update(:type => 'fetch_logs') - self[:tasks].grep(:description, 'ssh:%'). - update(:type => 'ssh') - self[:tasks].filter(:description => 'scan cloud'). - update(:type => 'cck_scan') - self[:tasks].filter(:description => 'apply resolutions'). - update(:type => 'cck_apply') - self[:tasks].filter(:description => 'retrieve vm-stats'). - update(:type => 'vms') - self[:tasks].filter(:description => 'create release'). - update(:type => 'update_release') - self[:tasks].grep(:description, 'delete release:%'). - update(:type => 'delete_release') - self[:tasks].filter(:description => 'create stemcell'). - update(:type => 'update_stemcell') - self[:tasks].grep(:description, 'delete stemcell:%'). - update(:type => 'delete_stemcell') - - alter_table :tasks do - set_column_allow_null :type, false - end - end - - down do - alter_table :tasks do - remove_column :type - drop_index :description - end - end -end diff --git a/src/bosh-director/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb b/src/bosh-director/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb deleted file mode 100644 index a5ea8826dc4..00000000000 --- a/src/bosh-director/db/migrations/director/20120614001930_delete_redundant_deployment_release_relation.rb +++ /dev/null @@ -1,32 +0,0 @@ -Sequel.migration do - up do - drop_table :deployments_releases - end - - down do - create_table :deployments_releases do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false - foreign_key :release_id, :releases, :null => false - unique [:deployment_id, :release_id] - end - - # Keeping manual track of (release_id, deployment_id) tuples - # to avoid having to handle violated uniqueness constraint - seen_ids = Set.new - - self[:deployments_release_versions].each do |drv| - rv = self[:release_versions].first(:id => drv[:release_version_id]) - - unless seen_ids.include?([drv[:deployment_id], rv[:release_id]]) - attrs = { - :release_id => rv[:release_id], - :deployment_id => drv[:deployment_id] - } - - self[:deployments_releases].insert(attrs) - seen_ids << [drv[:deployment_id], rv[:release_id]] - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb b/src/bosh-director/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb deleted file mode 100644 index c85e071582c..00000000000 --- a/src/bosh-director/db/migrations/director/20120822004528_add_fingerprint_to_templates_and_packages.rb +++ /dev/null @@ -1,15 +0,0 @@ -Sequel.migration do - change do - alter_table(:packages) do - add_column :fingerprint, String - add_index :fingerprint - add_index :sha1 - end - - alter_table(:templates) do - add_column :fingerprint, String - add_index :fingerprint - add_index :sha1 - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20120830191244_add_properties_to_templates.rb b/src/bosh-director/db/migrations/director/20120830191244_add_properties_to_templates.rb deleted file mode 100644 index 4133fcf508f..00000000000 --- a/src/bosh-director/db/migrations/director/20120830191244_add_properties_to_templates.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:templates) do - add_column :properties_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20121106190739_persist_vm_env.rb b/src/bosh-director/db/migrations/director/20121106190739_persist_vm_env.rb deleted file mode 100644 index cbea1e8667a..00000000000 --- a/src/bosh-director/db/migrations/director/20121106190739_persist_vm_env.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:vms) do - add_column :env_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb b/src/bosh-director/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb deleted file mode 100644 index b6d0a095168..00000000000 --- a/src/bosh-director/db/migrations/director/20130222232131_add_sha1_to_stemcells.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:stemcells) do - add_column :sha1, String - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb b/src/bosh-director/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb deleted file mode 100644 index 4287c79bb84..00000000000 --- a/src/bosh-director/db/migrations/director/20130312211407_add_commit_hash_to_release_versions.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - up do - alter_table :release_versions do - add_column :commit_hash, String - set_column_default :commit_hash, 'unknown' - - add_column :uncommitted_changes, TrueClass - set_column_default :uncommitted_changes, false - end - self[:release_versions].update(commit_hash: 'unknown', uncommitted_changes: false) - end - - down do - alter_table :release_versions do - drop_column :commit_hash - drop_column :uncommitted_changes - end - end -end diff --git a/src/bosh-director/db/migrations/director/20130409235338_snapshot.rb b/src/bosh-director/db/migrations/director/20130409235338_snapshot.rb deleted file mode 100644 index 68d948ca309..00000000000 --- a/src/bosh-director/db/migrations/director/20130409235338_snapshot.rb +++ /dev/null @@ -1,15 +0,0 @@ -Sequel.migration do - up do - create_table :snapshots do - primary_key :id - foreign_key :persistent_disk_id, :persistent_disks, :null => false - Boolean :clean, :default => false - Time :created_at, :null => false - String :snapshot_cid, :unique => true, :null => false - end - end - - down do - drop_table :snapshots - end -end diff --git a/src/bosh-director/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb b/src/bosh-director/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb deleted file mode 100644 index cf62b07170d..00000000000 --- a/src/bosh-director/db/migrations/director/20130530164918_add_paused_flag_to_instance.rb +++ /dev/null @@ -1,14 +0,0 @@ -Sequel.migration do - up do - alter_table :instances do - add_column :resurrection_paused, TrueClass - set_column_default :resurrection_paused, false - end - end - - down do - alter_table :instances do - drop_column :resurrection_paused - end - end -end diff --git a/src/bosh-director/db/migrations/director/20130531172604_add_director_attributes.rb b/src/bosh-director/db/migrations/director/20130531172604_add_director_attributes.rb deleted file mode 100644 index 7c2ba2f474d..00000000000 --- a/src/bosh-director/db/migrations/director/20130531172604_add_director_attributes.rb +++ /dev/null @@ -1,12 +0,0 @@ -Sequel.migration do - up do - create_table(:director_attributes) do - String :uuid, unique: true, null: false, primary_key: true - end - end - - down do - drop_table(:director_attributes) - end - -end diff --git a/src/bosh-director/db/migrations/director/20131121182231_add_rendered_templates_archives.rb b/src/bosh-director/db/migrations/director/20131121182231_add_rendered_templates_archives.rb deleted file mode 100644 index 58570432685..00000000000 --- a/src/bosh-director/db/migrations/director/20131121182231_add_rendered_templates_archives.rb +++ /dev/null @@ -1,16 +0,0 @@ -Sequel.migration do - change do - create_table :rendered_templates_archives do - primary_key :id - foreign_key :instance_id, :instances, null: false - - String :blob_id, null: false - String :checksum, null: false - - Time :created_at, null: false - - index :blob_id - index :created_at - end - end -end diff --git a/src/bosh-director/db/migrations/director/20131125232201_rename_rendered_templates_archives_blob_id_and_checksum_columns.rb b/src/bosh-director/db/migrations/director/20131125232201_rename_rendered_templates_archives_blob_id_and_checksum_columns.rb deleted file mode 100644 index f8b0e4ada79..00000000000 --- a/src/bosh-director/db/migrations/director/20131125232201_rename_rendered_templates_archives_blob_id_and_checksum_columns.rb +++ /dev/null @@ -1,17 +0,0 @@ -Sequel.migration do - change do - drop_table(:rendered_templates_archives) - - create_table(:rendered_templates_archives) do - primary_key :id - foreign_key :instance_id, :instances, null: false - - String :blobstore_id, null: false - String :sha1, null: false - String :content_sha1, null: false - Time :created_at, null: false - - index :created_at - end - end -end diff --git a/src/bosh-director/db/migrations/director/20140116002324_pivot_director_attributes.rb b/src/bosh-director/db/migrations/director/20140116002324_pivot_director_attributes.rb deleted file mode 100644 index 59754b81b2c..00000000000 --- a/src/bosh-director/db/migrations/director/20140116002324_pivot_director_attributes.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - rename_table(:director_attributes, :old_director_attributes) - - create_table(:director_attributes) do - String :name, unique: true, null: false, primary_key: true - String :value - end - - # Some directors might have created multiple records. - # Only the first record is ever used after every director restart. - old_attribute = self[:old_director_attributes].first - if old_attribute - self[:director_attributes].insert(name: 'uuid', value: old_attribute[:uuid]) - end - - drop_table(:old_director_attributes) - end -end diff --git a/src/bosh-director/db/migrations/director/20140124225348_proper_pk_for_attributes.rb b/src/bosh-director/db/migrations/director/20140124225348_proper_pk_for_attributes.rb deleted file mode 100644 index a231a497a76..00000000000 --- a/src/bosh-director/db/migrations/director/20140124225348_proper_pk_for_attributes.rb +++ /dev/null @@ -1,15 +0,0 @@ -Sequel.migration do - change do - add_column :director_attributes, :temp_name, String, null: true - self[:director_attributes].update(temp_name: :name) - - alter_table :director_attributes do - drop_column :name - rename_column :temp_name, :name - add_index [:name], unique:true, name: 'unique_attribute_name' - set_column_not_null :name - - add_primary_key :id - end - end -end diff --git a/src/bosh-director/db/migrations/director/20140731215410_increase_text_limit_for_data_columns.rb b/src/bosh-director/db/migrations/director/20140731215410_increase_text_limit_for_data_columns.rb deleted file mode 100644 index 559f6e0f4a1..00000000000 --- a/src/bosh-director/db/migrations/director/20140731215410_increase_text_limit_for_data_columns.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'digest/sha1' - -Sequel.migration do - change do - affected_constraint = [:package_id, :stemcell_id, :dependency_key] - constraint = self.indexes(:compiled_packages).find do |_, v| - v[:columns] == affected_constraint - end - - if constraint - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table(:compiled_packages) do - drop_index affected_constraint, name: constraint.first - end - else - alter_table(:compiled_packages) do - drop_constraint constraint.first - end - end - end - - alter_table(:compiled_packages) do - set_column_type :dependency_key, String, null: false, text: true - - add_column :dependency_key_sha1, String, null: true - end - - - self[:compiled_packages].each do |row| - self[:compiled_packages].filter(:id => row[:id]).update( - :dependency_key_sha1 => ::Digest::SHA1.hexdigest(row[:dependency_key]) - ) - end - - # enforcing dependency_key_sha1 to be not null after adding values to old data - alter_table(:compiled_packages) do - set_column_not_null :dependency_key_sha1 - - # Dependency key is part of unique constraint since different - # dependencies uniquely identify compiled package - add_index [:package_id, :stemcell_id, :dependency_key_sha1], unique: true, name: 'package_stemcell_dependency_key_sha1_idx' - end - - alter_table(:deployment_properties) do - set_column_type :value, String, null: false, text: true - end - - alter_table(:director_attributes) do - set_column_type :value, String, text: true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20141204234517_add_cloud_properties_to_persistent_disk.rb b/src/bosh-director/db/migrations/director/20141204234517_add_cloud_properties_to_persistent_disk.rb deleted file mode 100644 index 21545de5513..00000000000 --- a/src/bosh-director/db/migrations/director/20141204234517_add_cloud_properties_to_persistent_disk.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:persistent_disks) do - add_column :cloud_properties_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150102234124_denormalize_task_user_id_to_task_username.rb b/src/bosh-director/db/migrations/director/20150102234124_denormalize_task_user_id_to_task_username.rb deleted file mode 100644 index b0bdaf87e50..00000000000 --- a/src/bosh-director/db/migrations/director/20150102234124_denormalize_task_user_id_to_task_username.rb +++ /dev/null @@ -1,38 +0,0 @@ -Sequel.migration do - up do - # mysql doesn't let us drop tasks' user_id column because it has a foreign key, - # and sequel won't let us drop the foreign key, so we're recreating the table - # from scratch. Sorry. - - create_table :tasks_new do - primary_key :id - String :state, :null => false - Time :timestamp, :null => false - String :description, :null => false - String :result, :text => true, :null => true - String :output, :null => true - Time :checkpoint_time - String :type, :null => false - String :username, :null => true - end - - run "INSERT INTO tasks_new - (state, timestamp, description, result, output, checkpoint_time, type, username) - SELECT t.state, t.timestamp, t.description, t.result, t.output, t.checkpoint_time, t.type, u.username - FROM tasks t - LEFT OUTER JOIN users u ON t.user_id = u.id" - - drop_table :tasks - rename_table :tasks_new, :tasks - - alter_table :tasks do - add_index :state - add_index :timestamp - add_index :description - end - end - - down do - raise Sequel::Error, "Irreversible migration, tasks:user_id might contain nulls so we cannot enforce 'not null' constraint" - end -end diff --git a/src/bosh-director/db/migrations/director/20150223222605_increase_manifest_text_limit.rb b/src/bosh-director/db/migrations/director/20150223222605_increase_manifest_text_limit.rb deleted file mode 100644 index f893e3575eb..00000000000 --- a/src/bosh-director/db/migrations/director/20150223222605_increase_manifest_text_limit.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table :deployments do - set_column_type :manifest, 'longtext' - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150224193313_use_larger_text_types.rb b/src/bosh-director/db/migrations/director/20150224193313_use_larger_text_types.rb deleted file mode 100644 index 4a4f4336e46..00000000000 --- a/src/bosh-director/db/migrations/director/20150224193313_use_larger_text_types.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - set_column_type :tasks, :result, 'longtext' - set_column_type :vms, :apply_spec_json, 'longtext' - set_column_type :templates, :properties_json, 'longtext' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150331002413_add_cloud_configs.rb b/src/bosh-director/db/migrations/director/20150331002413_add_cloud_configs.rb deleted file mode 100644 index ae512e9540e..00000000000 --- a/src/bosh-director/db/migrations/director/20150331002413_add_cloud_configs.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - adapter_scheme = self.adapter_scheme - - create_table :cloud_configs do - primary_key :id - - if [:mysql2, :mysql].include?(adapter_scheme) - longtext :properties - else - text :properties - end - - Time :created_at, null: false - - index :created_at - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150401184803_add_cloud_config_to_deployments.rb b/src/bosh-director/db/migrations/director/20150401184803_add_cloud_config_to_deployments.rb deleted file mode 100644 index 52e57801dfb..00000000000 --- a/src/bosh-director/db/migrations/director/20150401184803_add_cloud_config_to_deployments.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:deployments) do - add_foreign_key :cloud_config_id, :cloud_configs - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150513225143_ip_addresses.rb b/src/bosh-director/db/migrations/director/20150513225143_ip_addresses.rb deleted file mode 100644 index e9c218977fe..00000000000 --- a/src/bosh-director/db/migrations/director/20150513225143_ip_addresses.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - change do - create_table :ip_addresses do - primary_key :id - String :network_name - Bignum :address, unique: true - Boolean :static - foreign_key :instance_id, :instances - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150611193110_add_trusted_certs_sha1_to_vms.rb b/src/bosh-director/db/migrations/director/20150611193110_add_trusted_certs_sha1_to_vms.rb deleted file mode 100644 index 62e4e2f74e8..00000000000 --- a/src/bosh-director/db/migrations/director/20150611193110_add_trusted_certs_sha1_to_vms.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'digest/sha1' - -Sequel.migration do - change do - alter_table(:vms) do - add_column :trusted_certs_sha1, String, { :default => ::Digest::SHA1.hexdigest('') } - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150619135210_add_os_name_and_version_to_stemcells.rb b/src/bosh-director/db/migrations/director/20150619135210_add_os_name_and_version_to_stemcells.rb deleted file mode 100644 index 528ef21e78c..00000000000 --- a/src/bosh-director/db/migrations/director/20150619135210_add_os_name_and_version_to_stemcells.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:stemcells) do - add_column :operating_system, String - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20150702004608_add_links.rb b/src/bosh-director/db/migrations/director/20150702004608_add_links.rb deleted file mode 100644 index 65ff5d53c2b..00000000000 --- a/src/bosh-director/db/migrations/director/20150702004608_add_links.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table(:templates) do - add_column :requires_json, String - add_column :provides_json, String - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150708231924_add_link_spec.rb b/src/bosh-director/db/migrations/director/20150708231924_add_link_spec.rb deleted file mode 100644 index 706b79745cc..00000000000 --- a/src/bosh-director/db/migrations/director/20150708231924_add_link_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:deployments) do - add_column :link_spec_json, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150716170926_allow_null_on_blobstore_id_and_sha1_on_package.rb b/src/bosh-director/db/migrations/director/20150716170926_allow_null_on_blobstore_id_and_sha1_on_package.rb deleted file mode 100644 index c951c85d183..00000000000 --- a/src/bosh-director/db/migrations/director/20150716170926_allow_null_on_blobstore_id_and_sha1_on_package.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table(:packages) do - set_column_allow_null :blobstore_id, true - set_column_allow_null :sha1, true - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20150724183256_add_debugging_to_ip_addresses.rb b/src/bosh-director/db/migrations/director/20150724183256_add_debugging_to_ip_addresses.rb deleted file mode 100644 index 7ffd74e3ef3..00000000000 --- a/src/bosh-director/db/migrations/director/20150724183256_add_debugging_to_ip_addresses.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table(:ip_addresses) do - add_column :created_at, Time - add_column :task_id, String - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150730225029_add_uuid_to_instances.rb b/src/bosh-director/db/migrations/director/20150730225029_add_uuid_to_instances.rb deleted file mode 100644 index b5090208947..00000000000 --- a/src/bosh-director/db/migrations/director/20150730225029_add_uuid_to_instances.rb +++ /dev/null @@ -1,16 +0,0 @@ -require('securerandom') - -Sequel.migration do - up do - alter_table(:instances) do - add_column :uuid, String, unique: true - end - self[:instances].each { |row| self[:instances].filter(id: row[:id]).update(uuid: SecureRandom.uuid) } - end - - down do - alter_table(:instances) do - drop_column :uuid - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150803215805_add_availabililty_zone_and_cloud_properties_to_instances.rb b/src/bosh-director/db/migrations/director/20150803215805_add_availabililty_zone_and_cloud_properties_to_instances.rb deleted file mode 100644 index b3d256530a1..00000000000 --- a/src/bosh-director/db/migrations/director/20150803215805_add_availabililty_zone_and_cloud_properties_to_instances.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :availability_zone, String - add_column :cloud_properties, String, :text => true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150804211419_add_compilation_flag_to_instance.rb b/src/bosh-director/db/migrations/director/20150804211419_add_compilation_flag_to_instance.rb deleted file mode 100644 index 60a7c81b90d..00000000000 --- a/src/bosh-director/db/migrations/director/20150804211419_add_compilation_flag_to_instance.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :compilation, TrueClass, default: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20150918003455_add_bootstrap_node_to_instance.rb b/src/bosh-director/db/migrations/director/20150918003455_add_bootstrap_node_to_instance.rb deleted file mode 100644 index 93caf624c25..00000000000 --- a/src/bosh-director/db/migrations/director/20150918003455_add_bootstrap_node_to_instance.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :bootstrap, TrueClass, default: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20151008232214_add_dns_records.rb b/src/bosh-director/db/migrations/director/20151008232214_add_dns_records.rb deleted file mode 100644 index 14d1f92f729..00000000000 --- a/src/bosh-director/db/migrations/director/20151008232214_add_dns_records.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :dns_records, String, text: true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20151015172551_add_orphan_disks_and_snapshots.rb b/src/bosh-director/db/migrations/director/20151015172551_add_orphan_disks_and_snapshots.rb deleted file mode 100644 index d7ff964159a..00000000000 --- a/src/bosh-director/db/migrations/director/20151015172551_add_orphan_disks_and_snapshots.rb +++ /dev/null @@ -1,29 +0,0 @@ -Sequel.migration do - up do - create_table(:orphan_disks) do - primary_key :id - String :disk_cid, :null => false, :unique => true - Integer :size - String :availability_zone - String :deployment_name, :null => false - String :instance_name, :null => false - String :cloud_properties_json, :text => true - Time :orphaned_at, :null => false, :index => true - end - - create_table(:orphan_snapshots) do - primary_key :id - foreign_key :orphan_disk_id, :orphan_disks, :null => false - String :snapshot_cid, :unique => true, :null => false - Boolean :clean, :default => false - Time :created_at, :null => false - Time :orphaned_at, :null => false, :index => true - end - end - - down do - drop_table(:orphan_snapshots) - drop_table(:orphan_disks) - end -end - diff --git a/src/bosh-director/db/migrations/director/20151030222853_add_templates_to_instance.rb b/src/bosh-director/db/migrations/director/20151030222853_add_templates_to_instance.rb deleted file mode 100644 index d1c3b421f29..00000000000 --- a/src/bosh-director/db/migrations/director/20151030222853_add_templates_to_instance.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - up do - create_table(:instances_templates) do - primary_key :id - foreign_key :instance_id, :instances, :null => false - foreign_key :template_id, :templates, :null => false - unique [:instance_id, :template_id] - end - end -end diff --git a/src/bosh-director/db/migrations/director/20151031001039_add_spec_to_instance.rb b/src/bosh-director/db/migrations/director/20151031001039_add_spec_to_instance.rb deleted file mode 100644 index 4d6949b3b05..00000000000 --- a/src/bosh-director/db/migrations/director/20151031001039_add_spec_to_instance.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :spec_json, String, text: true - end - - self[:instances].each do |instance| - next unless instance[:vm_id] - - vm = self[:vms].filter(id: instance[:vm_id]).first - - self[:instances].filter(id: instance[:id]).update(spec_json: vm[:apply_spec_json]) - end - - alter_table(:vms) do - drop_column(:apply_spec_json) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20151109190602_rename_orphan_columns.rb b/src/bosh-director/db/migrations/director/20151109190602_rename_orphan_columns.rb deleted file mode 100644 index e8077d34a6f..00000000000 --- a/src/bosh-director/db/migrations/director/20151109190602_rename_orphan_columns.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - change do - alter_table :orphan_disks do - rename_column :orphaned_at, :created_at - end - - alter_table :orphan_snapshots do - drop_column :created_at - rename_column :orphaned_at, :created_at - add_column :snapshot_created_at, Time - end - end -end diff --git a/src/bosh-director/db/migrations/director/20151223172000_rename_requires_json.rb b/src/bosh-director/db/migrations/director/20151223172000_rename_requires_json.rb deleted file mode 100644 index c4bc8aa5b19..00000000000 --- a/src/bosh-director/db/migrations/director/20151223172000_rename_requires_json.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table :templates do - rename_column :requires_json, :consumes_json - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20151229184742_add_vm_attributes_to_instance.rb b/src/bosh-director/db/migrations/director/20151229184742_add_vm_attributes_to_instance.rb deleted file mode 100644 index 01017d599d0..00000000000 --- a/src/bosh-director/db/migrations/director/20151229184742_add_vm_attributes_to_instance.rb +++ /dev/null @@ -1,25 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :vm_cid, String, unique: true - add_column :agent_id, String, unique: true - add_column :credentials_json, String, :text => true - add_column :vm_env_json, String, :text => true - add_column :trusted_certs_sha1, String, { :default => ::Digest::SHA1.hexdigest('') } - end - - self[:instances].each do |instance| - next unless instance[:vm_id] - - vm = self[:vms].filter(id: instance[:vm_id]).first - - self[:instances].filter(id: instance[:id]).update( - vm_cid: vm[:cid], - agent_id: vm[:agent_id], - vm_env_json: vm[:env_json], - trusted_certs_sha1: vm[:trusted_certs_sha1], - credentials_json: vm[:credentials_json] - ) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160106162749_runtime_configs.rb b/src/bosh-director/db/migrations/director/20160106162749_runtime_configs.rb deleted file mode 100644 index 6e9ca758a01..00000000000 --- a/src/bosh-director/db/migrations/director/20160106162749_runtime_configs.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - adapter_scheme = self.adapter_scheme - - create_table :runtime_configs do - primary_key :id - - if [:mysql2, :mysql].include?(adapter_scheme) - longtext :properties - else - text :properties - end - - Time :created_at, null: false - - index :created_at - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160106163433_add_runtime_configs_to_deployments.rb b/src/bosh-director/db/migrations/director/20160106163433_add_runtime_configs_to_deployments.rb deleted file mode 100644 index 77f7475db77..00000000000 --- a/src/bosh-director/db/migrations/director/20160106163433_add_runtime_configs_to_deployments.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:deployments) do - add_foreign_key :runtime_config_id, :runtime_configs - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160108191637_drop_vm_env_json_from_instance.rb b/src/bosh-director/db/migrations/director/20160108191637_drop_vm_env_json_from_instance.rb deleted file mode 100644 index 7f8cfc9155d..00000000000 --- a/src/bosh-director/db/migrations/director/20160108191637_drop_vm_env_json_from_instance.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - drop_column :vm_env_json - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160121003800_drop_vms_fkeys.rb b/src/bosh-director/db/migrations/director/20160121003800_drop_vms_fkeys.rb deleted file mode 100644 index 8c8de507830..00000000000 --- a/src/bosh-director/db/migrations/director/20160121003800_drop_vms_fkeys.rb +++ /dev/null @@ -1,12 +0,0 @@ -Sequel.migration do - change do - - # newer versions of sequel support drop_foreign_key but the version breaks tests - if [:mysql2, :mysql].include?(adapter_scheme) - run('alter table vms drop FOREIGN KEY vms_ibfk_1') - elsif [:postgres].include?(adapter_scheme) - run('alter table vms drop constraint vms_deployment_id_fkey') - end - - end -end diff --git a/src/bosh-director/db/migrations/director/20160202162216_add_post_start_completed_to_instance.rb b/src/bosh-director/db/migrations/director/20160202162216_add_post_start_completed_to_instance.rb deleted file mode 100644 index f4d0f226ffd..00000000000 --- a/src/bosh-director/db/migrations/director/20160202162216_add_post_start_completed_to_instance.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column :post_start_completed, TrueClass, default: true - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version.rb b/src/bosh-director/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version.rb deleted file mode 100644 index 65b1a074a34..00000000000 --- a/src/bosh-director/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version.rb +++ /dev/null @@ -1,55 +0,0 @@ -Sequel.migration do - change do - alter_table(:compiled_packages) do - add_column :stemcell_os, String - add_column :stemcell_version, String - end - - self[:compiled_packages].each do |compiled_package| - next unless compiled_package[:stemcell_id] - - stemcell = self[:stemcells].filter(id: compiled_package[:stemcell_id]).first - stemcell_os = stemcell[:operating_system].to_s.empty? ? stemcell[:name] : stemcell[:operating_system] - - self[:compiled_packages].filter(id: compiled_package[:id]).update( - stemcell_os: stemcell_os, - stemcell_version: stemcell[:version] - ) - end - - if [:mysql2, :mysql, :postgres].include?(adapter_scheme) - stemcell_foreign_keys = foreign_key_list(:compiled_packages).select { |constraint| constraint.fetch(:columns).include?(:stemcell_id) } - raise 'Failed to run migration, found more than 1 stemcell foreign key' if stemcell_foreign_keys.size != 1 - stemcell_foreign_key_name = stemcell_foreign_keys.first.fetch(:name) - - build_indexes = indexes(:compiled_packages).select { |_, value| value.fetch(:columns) == [:package_id, :stemcell_id, :build] } - if [:mysql2, :mysql].include?(adapter_scheme) - raise 'Failed to run migration, found more than 1 build index' if build_indexes.size != 1 - # build_indexes is an array, where each element is an array with first element being the name of index - build_index = build_indexes.first.first - alter_table(:compiled_packages) do - drop_index(nil, name: build_index) - end - elsif [:postgres].include?(adapter_scheme) - build_index = build_indexes.empty? ? 'compiled_packages_package_id_stemcell_id_build_key' : build_indexes.first.first - alter_table(:compiled_packages) do - drop_constraint(build_index) - end - end - - stemcell_indexes = indexes(:compiled_packages).select { |_, value| value.fetch(:columns) == [:package_id, :stemcell_id, :dependency_key_sha1]} - stemcell_index = stemcell_indexes.empty? ? 'package_stemcell_dependency_key_sha1_idx' : stemcell_indexes.first.first - - alter_table(:compiled_packages) do - drop_constraint(stemcell_foreign_key_name, :type => :foreign_key) - add_index [:package_id, :stemcell_os, :stemcell_version, :build], unique: true, name: 'package_stemcell_build_idx' - add_index [:package_id, :stemcell_os, :stemcell_version, :dependency_key_sha1], unique: true, name: 'package_stemcell_dependency_idx' - drop_index(nil, name: stemcell_index) - end - end - - alter_table(:compiled_packages) do - drop_column :stemcell_id - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160211174110_add_events.rb b/src/bosh-director/db/migrations/director/20160211174110_add_events.rb deleted file mode 100644 index e1a349a00b1..00000000000 --- a/src/bosh-director/db/migrations/director/20160211174110_add_events.rb +++ /dev/null @@ -1,22 +0,0 @@ -Sequel.migration do - up do - create_table :events do - primary_key :id - Integer :parent_id - String :user, :null => false - Time :timestamp, :index => true, :null => false - String :action, :null => false - String :object_type, :null => false - String :object_name - String :error, :text => true - String :task - String :deployment - String :instance - String :context_json, :text => true - end - end - - down do - drop_table :events - end -end diff --git a/src/bosh-director/db/migrations/director/20160211193904_add_scopes_to_deployment.rb b/src/bosh-director/db/migrations/director/20160211193904_add_scopes_to_deployment.rb deleted file mode 100644 index 68fab878a51..00000000000 --- a/src/bosh-director/db/migrations/director/20160211193904_add_scopes_to_deployment.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:deployments) do - add_column :scopes, String, default: 'bosh.admin' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160219175840_add_column_teams_to_deployments.rb b/src/bosh-director/db/migrations/director/20160219175840_add_column_teams_to_deployments.rb deleted file mode 100644 index ee3c80e38f3..00000000000 --- a/src/bosh-director/db/migrations/director/20160219175840_add_column_teams_to_deployments.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table(:deployments) do - drop_column(:scopes) - add_column :teams, String - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160224222508_add_deployment_name_to_task.rb b/src/bosh-director/db/migrations/director/20160224222508_add_deployment_name_to_task.rb deleted file mode 100644 index 96b74aeb011..00000000000 --- a/src/bosh-director/db/migrations/director/20160224222508_add_deployment_name_to_task.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_column :deployment_name, String, default: nil - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160225182206_rename_post_start_completed.rb b/src/bosh-director/db/migrations/director/20160225182206_rename_post_start_completed.rb deleted file mode 100644 index 0f421249567..00000000000 --- a/src/bosh-director/db/migrations/director/20160225182206_rename_post_start_completed.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table :instances do - rename_column :post_start_completed, :update_completed - set_column_default :update_completed, false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160324181932_create_delayed_jobs.rb b/src/bosh-director/db/migrations/director/20160324181932_create_delayed_jobs.rb deleted file mode 100644 index 0580f86d7c2..00000000000 --- a/src/bosh-director/db/migrations/director/20160324181932_create_delayed_jobs.rb +++ /dev/null @@ -1,22 +0,0 @@ -Sequel.migration do - up do - create_table :delayed_jobs, force: true do - primary_key :id - Integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue - Integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. - String :handler, :text => true, null: false # YAML-encoded string of the object that will do work - String :last_error, :text => true # reason for last failure (See Note below) - Time :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. - Time :locked_at # Set when a client is working on this object - Time :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) - String :locked_by # Who is working on this object (if locked) - String :queue # The name of the queue this job is in - end - - add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" - end - - down do - drop_table :delayed_jobs - end -end diff --git a/src/bosh-director/db/migrations/director/20160324182211_add_locks.rb b/src/bosh-director/db/migrations/director/20160324182211_add_locks.rb deleted file mode 100644 index 72f3d8360c8..00000000000 --- a/src/bosh-director/db/migrations/director/20160324182211_add_locks.rb +++ /dev/null @@ -1,15 +0,0 @@ -Sequel.migration do - up do - create_table :locks do - primary_key :id - Time :expired_at, :null => false - String :name, :unique => true, :null => false - String :uid, :unique => true, :null => false - index :name, :unique => true - end - end - - down do - drop_table :locks - end -end diff --git a/src/bosh-director/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false.rb b/src/bosh-director/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false.rb deleted file mode 100644 index 4d2aa2dd634..00000000000 --- a/src/bosh-director/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'json' - -Sequel.migration do - up do - self[:instances].all do |instance| - unless instance[:spec_json].nil? - spec = JSON.parse(instance[:spec_json]) - if !spec['update'].nil? && spec['update'].has_key?('serial') && spec['update']['serial'].nil? - spec['update']['serial'] = false - self[:instances].where(id: instance[:id]).update(spec_json: JSON.generate(spec)) - end - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160331225404_backfill_stemcell_os.rb b/src/bosh-director/db/migrations/director/20160331225404_backfill_stemcell_os.rb deleted file mode 100644 index 2e7dd8f02d1..00000000000 --- a/src/bosh-director/db/migrations/director/20160331225404_backfill_stemcell_os.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - up do - self[:stemcells].all do |stemcell| - if stemcell[:operating_system].nil? || stemcell[:operating_system] == '' - self[:stemcells].where(id: stemcell[:id]).update(operating_system: stemcell[:name]) - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160411104407_add_task_started_at.rb b/src/bosh-director/db/migrations/director/20160411104407_add_task_started_at.rb deleted file mode 100644 index 166a2252f71..00000000000 --- a/src/bosh-director/db/migrations/director/20160411104407_add_task_started_at.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_column(:started_at, Time) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160414183654_set_teams_on_task.rb b/src/bosh-director/db/migrations/director/20160414183654_set_teams_on_task.rb deleted file mode 100644 index 2f1969c4fef..00000000000 --- a/src/bosh-director/db/migrations/director/20160414183654_set_teams_on_task.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_column(:teams, String) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160427164345_add_teams.rb b/src/bosh-director/db/migrations/director/20160427164345_add_teams.rb deleted file mode 100644 index 5d8c7d782d8..00000000000 --- a/src/bosh-director/db/migrations/director/20160427164345_add_teams.rb +++ /dev/null @@ -1,48 +0,0 @@ -Sequel.migration do - up do - create_table :teams do - primary_key :id - String :name, :unique => true, :null => false - end - - create_table :deployments_teams do - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - foreign_key :team_id, :teams, :null => false, :on_delete => :cascade - unique [:deployment_id, :team_id] - end - - deployments_with_teams = self[:deployments].reject { |d| d[:teams].nil? } - team_names = deployments_with_teams - .map { |d| d[:teams].split(',') } - .flatten - .uniq - .map { |team| [team] } - - self[:teams].import([:name], team_names) - - deployments_with_teams.each do |d| - deployment_teams = d[:teams] - .split(',') - .map do |team_name| - team = self[:teams].filter({name: team_name}).first - [d[:id], team[:id]] - end - - self[:deployments_teams].import([:deployment_id, :team_id], deployment_teams) - end - - alter_table(:deployments) do - drop_column :teams - end - - create_table :tasks_teams do - foreign_key :task_id, :tasks, :null => false, :on_delete => :cascade - foreign_key :team_id, :teams, :null => false, :on_delete => :cascade - unique [:task_id, :team_id] - end - - alter_table(:tasks) do - drop_column :teams - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160511191928_ephemeral_blobs.rb b/src/bosh-director/db/migrations/director/20160511191928_ephemeral_blobs.rb deleted file mode 100644 index 0828e9e4a26..00000000000 --- a/src/bosh-director/db/migrations/director/20160511191928_ephemeral_blobs.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - change do - create_table :ephemeral_blobs do - primary_key :id - String :blobstore_id, :null => false - String :sha1, :null => false - Time :created_at, null: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160513102035_add_tracking_to_instance.rb b/src/bosh-director/db/migrations/director/20160513102035_add_tracking_to_instance.rb deleted file mode 100644 index b671b5d18d9..00000000000 --- a/src/bosh-director/db/migrations/director/20160513102035_add_tracking_to_instance.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - add_column(:ignore, TrueClass, :default => false) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160531164756_add_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20160531164756_add_local_dns_blobs.rb deleted file mode 100644 index b29080971a5..00000000000 --- a/src/bosh-director/db/migrations/director/20160531164756_add_local_dns_blobs.rb +++ /dev/null @@ -1,18 +0,0 @@ -Sequel.migration do - up do - create_table :local_dns_blobs do - primary_key :id - String :blobstore_id, :null => false - String :sha1, :null => false - Time :created_at, null: false - end - - alter_table :local_dns_blobs do - add_index [:blobstore_id, :sha1], unique: true, name: 'blobstore_id_sha1_idx' - end - end - - down do - drop_table :local_dns_blobs - end -end diff --git a/src/bosh-director/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql.rb b/src/bosh-director/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql.rb deleted file mode 100644 index 9dd64c2156c..00000000000 --- a/src/bosh-director/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql.rb +++ /dev/null @@ -1,21 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - set_column_type :compiled_packages, :dependency_key, 'longtext' - set_column_type :deployment_problems, :data_json, 'longtext' - set_column_type :deployment_properties, :value, 'longtext' - set_column_type :deployments, :link_spec_json, 'longtext' - set_column_type :director_attributes, :value, 'longtext' - set_column_type :instances, :cloud_properties, 'longtext' - set_column_type :instances, :dns_records, 'longtext' - set_column_type :instances, :spec_json, 'longtext' - set_column_type :instances, :credentials_json, 'longtext' - set_column_type :orphan_disks, :cloud_properties_json, 'longtext' - set_column_type :packages, :dependency_set_json, 'longtext' - set_column_type :persistent_disks, :cloud_properties_json, 'longtext' - set_column_type :templates, :package_names_json, 'longtext' - set_column_type :templates, :logs_json, 'longtext' - set_column_type :templates, :properties_json, 'longtext' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields.rb b/src/bosh-director/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields.rb deleted file mode 100644 index f035b96c52b..00000000000 --- a/src/bosh-director/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - set_column_type :events, :error, 'longtext' - set_column_type :events, :context_json, 'longtext' - set_column_type :delayed_jobs, :handler, 'longtext' - set_column_type :delayed_jobs, :last_error, 'longtext' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160706131605_change_events_id_type.rb b/src/bosh-director/db/migrations/director/20160706131605_change_events_id_type.rb deleted file mode 100644 index 4c963d76015..00000000000 --- a/src/bosh-director/db/migrations/director/20160706131605_change_events_id_type.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - unless [:sqlite].include?(adapter_scheme) - set_column_type :events, :id, :Bignum - set_column_type :events, :parent_id, :Bignum - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160708234509_add_local_dns_records.rb b/src/bosh-director/db/migrations/director/20160708234509_add_local_dns_records.rb deleted file mode 100644 index 929e63f0731..00000000000 --- a/src/bosh-director/db/migrations/director/20160708234509_add_local_dns_records.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - up do - create_table :local_dns_records do - primary_key :id - String :name, :null => false - String :ip, :null => false - foreign_key :instance_id, :instances, :null => false, :on_delete => :cascade - end - - alter_table :local_dns_records do - add_index [:name, :ip], unique: true, name: 'name_ip_idx' - end - end - - down do - drop_table :local_dns_records - end -end - diff --git a/src/bosh-director/db/migrations/director/20160712171230_add_version_to_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20160712171230_add_version_to_local_dns_blobs.rb deleted file mode 100644 index 52a0e793f39..00000000000 --- a/src/bosh-director/db/migrations/director/20160712171230_add_version_to_local_dns_blobs.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:local_dns_blobs) do - add_column(:version, Integer) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160725090007_add_cpi_configs.rb b/src/bosh-director/db/migrations/director/20160725090007_add_cpi_configs.rb deleted file mode 100644 index 091c23b4d10..00000000000 --- a/src/bosh-director/db/migrations/director/20160725090007_add_cpi_configs.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - adapter_scheme = self.adapter_scheme - - create_table :cpi_configs do - primary_key :id - - if [:mysql2, :mysql].include?(adapter_scheme) - longtext :properties - else - text :properties - end - - Time :created_at, null: false - - index :created_at - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160803151600_add_name_to_persistent_disks.rb b/src/bosh-director/db/migrations/director/20160803151600_add_name_to_persistent_disks.rb deleted file mode 100644 index 2d1beacac72..00000000000 --- a/src/bosh-director/db/migrations/director/20160803151600_add_name_to_persistent_disks.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:persistent_disks) do - add_column(:name, String, default: '') - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160817135953_add_cpi_to_stemcells.rb b/src/bosh-director/db/migrations/director/20160817135953_add_cpi_to_stemcells.rb deleted file mode 100644 index c46b852a9bb..00000000000 --- a/src/bosh-director/db/migrations/director/20160817135953_add_cpi_to_stemcells.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:stemcells) do - add_column(:cpi, String, default: '') - end - end -end diff --git a/src/bosh-director/db/migrations/director/20160818112257_change_stemcell_unique_key.rb b/src/bosh-director/db/migrations/director/20160818112257_change_stemcell_unique_key.rb deleted file mode 100644 index aae24495843..00000000000 --- a/src/bosh-director/db/migrations/director/20160818112257_change_stemcell_unique_key.rb +++ /dev/null @@ -1,24 +0,0 @@ -Sequel.migration do - change do - old_constraint = [:name, :version] - existing_constraint = self.indexes(:stemcells).find do |_, v| - v[:columns] == old_constraint - end - - if existing_constraint - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table(:stemcells) do - drop_index old_constraint, name: existing_constraint.first - end - else - alter_table(:stemcells) do - drop_constraint existing_constraint.first - end - end - end - - alter_table(:stemcells) do - add_unique_constraint([:name, :version, :cpi], :name => 'stemcells_name_version_cpi_key') - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec.rb b/src/bosh-director/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec.rb deleted file mode 100644 index 9d15c39aeda..00000000000 --- a/src/bosh-director/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'json' -require 'yaml' - -Sequel.migration do - change do - self[:instances].all do |instance| - instance_spec_json = instance[:spec_json] - next if instance_spec_json == nil || instance_spec_json == "" - - spec_json = JSON.parse(instance_spec_json) - deployment = self[:deployments].where(id: instance[:deployment_id]).first - - deployment_manifest_yml = deployment[:manifest] - next if deployment_manifest_yml == nil || deployment_manifest_yml == "" - - manifest_hash = YAML.load(deployment_manifest_yml) - - groups = manifest_hash['jobs'] || manifest_hash['instance_groups'] - next if groups == nil - - group = groups.find { |instance_group| instance_group['name'] == instance[:job] } - next if group == nil - - spec_json['lifecycle'] = group['lifecycle'] || 'service' - self[:instances].where(id: instance[:id]).update(spec_json: JSON.dump(spec_json)) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20161128181900_add_logs_to_tasks.rb b/src/bosh-director/db/migrations/director/20161128181900_add_logs_to_tasks.rb deleted file mode 100644 index 6526c4e09a6..00000000000 --- a/src/bosh-director/db/migrations/director/20161128181900_add_logs_to_tasks.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - change do - alter_table(:tasks) do - add_column(:event_output, String, :text => true) - add_column(:result_output, String, :text => true) - end - - if [:mysql2, :mysql].include?(adapter_scheme) - set_column_type :tasks, :event_output, 'longtext' - set_column_type :tasks, :result_output, 'longtext' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20161209104649_add_context_id_to_tasks.rb b/src/bosh-director/db/migrations/director/20161209104649_add_context_id_to_tasks.rb deleted file mode 100644 index 7e05d4a95b2..00000000000 --- a/src/bosh-director/db/migrations/director/20161209104649_add_context_id_to_tasks.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - change do - alter_table :tasks do - add_column :context_id, String, size: 64, default: '', null: false - add_index :context_id - end - end -end diff --git a/src/bosh-director/db/migrations/director/20161221151107_allow_null_instance_id_local_dns.rb b/src/bosh-director/db/migrations/director/20161221151107_allow_null_instance_id_local_dns.rb deleted file mode 100644 index fe22674d6bf..00000000000 --- a/src/bosh-director/db/migrations/director/20161221151107_allow_null_instance_id_local_dns.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table :local_dns_records do - set_column_allow_null(:instance_id) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170104003158_add_agent_dns_version.rb b/src/bosh-director/db/migrations/director/20170104003158_add_agent_dns_version.rb deleted file mode 100644 index b003a9b4a8d..00000000000 --- a/src/bosh-director/db/migrations/director/20170104003158_add_agent_dns_version.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - change do - create_table :agent_dns_versions do - primary_key :id - String :agent_id, :unique => true, :null => false - Integer :dns_version, :default => 0, :null => false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170116235940_add_errand_runs.rb b/src/bosh-director/db/migrations/director/20170116235940_add_errand_runs.rb deleted file mode 100644 index 39643316c60..00000000000 --- a/src/bosh-director/db/migrations/director/20170116235940_add_errand_runs.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - db_type = adapter_scheme - create_table :errand_runs do - primary_key :id - - TrueClass :successful, :default => false - String :successful_configuration_hash, size: 512 - - if [:mysql2, :mysql].include?(db_type) - longtext :successful_packages_spec - else - String :successful_packages_spec, :text => true - end - - foreign_key :instance_id, :instances, :null => false, :on_delete => :cascade, :foreign_key_constraint_name => 'errands_instance_id_fkey' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170119202003_update_sha1_column_sizes.rb b/src/bosh-director/db/migrations/director/20170119202003_update_sha1_column_sizes.rb deleted file mode 100644 index 508347300ef..00000000000 --- a/src/bosh-director/db/migrations/director/20170119202003_update_sha1_column_sizes.rb +++ /dev/null @@ -1,49 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - - alter_table(:packages) do - drop_index :sha1 - set_column_type :sha1, String, size: 512 - add_index :sha1, name: 'packages_sha1_index' - end - - alter_table(:templates) do - drop_index :sha1 - set_column_type :sha1, String, size: 512 - add_index :sha1, name: 'templates_sha1_index' - end - - alter_table(:compiled_packages) do - set_column_type :sha1, String, size: 512 - end - - alter_table(:ephemeral_blobs) do - set_column_type :sha1, String, size: 512 - end - - alter_table(:stemcells) do - set_column_type :sha1, String, size: 512 - end - - index = indexes(:local_dns_blobs).detect { |name, _| name.to_s == 'blobstore_id_sha1_idx' } - - if !index.nil? - alter_table(:local_dns_blobs) do - drop_index(nil, name: 'blobstore_id_sha1_idx') - end - end - - alter_table(:local_dns_blobs) do - set_column_type :sha1, String, size: 512 - end - else - index = indexes(:local_dns_blobs).detect { |name, _| name.to_s == 'blobstore_id_sha1_idx' } - if !index.nil? - alter_table(:local_dns_blobs) do - drop_index(nil, name: 'blobstore_id_sha1_idx') - end - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170203212124_add_variables.rb b/src/bosh-director/db/migrations/director/20170203212124_add_variables.rb deleted file mode 100644 index 80a2b58a9b2..00000000000 --- a/src/bosh-director/db/migrations/director/20170203212124_add_variables.rb +++ /dev/null @@ -1,44 +0,0 @@ -Sequel.migration do - up do - create_table :variable_sets do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - Time :created_at, null: false, :index => true - end - - create_table :variables do - primary_key :id - String :variable_id, :null => false - String :variable_name, :null => false - foreign_key :variable_set_id, :variable_sets, :null => false, :on_delete => :cascade - index [:variable_set_id, :variable_name], :unique => true, :name => :variable_set_id_variable_name - end - - self[:deployments].each do |deployment| - self[:variable_sets].insert(deployment_id: deployment[:id], created_at: Time.now) - end - - alter_table(:instances) do - add_column :variable_set_id, Integer - end - - self[:instances].each do |instance| - variable_set = self[:variable_sets].filter(deployment_id: instance[:deployment_id]).first - self[:instances].where(id: instance[:id]).update(variable_set_id: variable_set[:id]) - end - - alter_table(:instances) do - set_column_not_null :variable_set_id - add_foreign_key [:variable_set_id], :variable_sets, :name=>:instance_table_variable_set_fkey - end - end - - down do - alter_table(:instances) do - drop_foreign_key :variable_set_id - end - - drop_table :variable_sets - drop_table :variables - end -end diff --git a/src/bosh-director/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs.rb deleted file mode 100644 index 027813f4898..00000000000 --- a/src/bosh-director/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - change do - index = indexes(:local_dns_blobs).detect { |name, _| name.to_s == 'blobstore_id_idx' } - if !index.nil? - alter_table(:local_dns_blobs) do - drop_index(nil, name: 'blobstore_id_idx') - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update.rb b/src/bosh-director/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update.rb deleted file mode 100644 index d0e4cb89740..00000000000 --- a/src/bosh-director/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - up do - alter_table(:instances) do - drop_foreign_key [:variable_set_id] - add_foreign_key [:variable_set_id], :variable_sets, :name=>:instance_table_variable_set_fkey - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170301192646_add_deployed_successfully_to_variable_sets.rb b/src/bosh-director/db/migrations/director/20170301192646_add_deployed_successfully_to_variable_sets.rb deleted file mode 100644 index 8550b0aa6dc..00000000000 --- a/src/bosh-director/db/migrations/director/20170301192646_add_deployed_successfully_to_variable_sets.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:variable_sets) do - add_column :deployed_successfully, TrueClass, :default => false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170303175054_expand_template_json_column_lengths.rb b/src/bosh-director/db/migrations/director/20170303175054_expand_template_json_column_lengths.rb deleted file mode 100644 index 4a64757bb34..00000000000 --- a/src/bosh-director/db/migrations/director/20170303175054_expand_template_json_column_lengths.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table(:templates) do - set_column_type :provides_json, 'longtext' - set_column_type :consumes_json, 'longtext' - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170306215659_expand_vms_json_column_lengths.rb b/src/bosh-director/db/migrations/director/20170306215659_expand_vms_json_column_lengths.rb deleted file mode 100644 index c8ff1fc70cd..00000000000 --- a/src/bosh-director/db/migrations/director/20170306215659_expand_vms_json_column_lengths.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - change do - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table(:vms) do - set_column_type :credentials_json, 'longtext' - set_column_type :env_json, 'longtext' - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records.rb b/src/bosh-director/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records.rb deleted file mode 100644 index b1468353a25..00000000000 --- a/src/bosh-director/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records.rb +++ /dev/null @@ -1,33 +0,0 @@ -Sequel.migration do - up do - alter_table(:local_dns_records) do - add_column :az, String - add_column :instance_group, String - add_column :network, String - add_column :deployment, String - end - - self[:local_dns_records].each do |local_dns_record| - next if local_dns_record[:instance_id] == nil - instance = self[:instances].first(id: local_dns_record[:instance_id]) - - begin - instance_spec_json = JSON.parse(instance[:spec_json]) - network = instance_spec_json['networks'].find do |_, network| - network['ip']== local_dns_record[:ip] - end - - network_name = network.first - rescue - network_name = '' - end - - self[:local_dns_records].where(id: local_dns_record[:id]).update({ - instance_group: instance[:job], - network: network_name, - deployment: self[:deployments].first(id: instance[:deployment_id])[:name], - az: instance[:availability_zone], - }) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170321151400_add_writable_to_variable_set.rb b/src/bosh-director/db/migrations/director/20170321151400_add_writable_to_variable_set.rb deleted file mode 100644 index c7ce2c7abf0..00000000000 --- a/src/bosh-director/db/migrations/director/20170321151400_add_writable_to_variable_set.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:variable_sets) do - add_column :writable, TrueClass, :default => false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170328224049_associate_vm_info_with_vms_table.rb b/src/bosh-director/db/migrations/director/20170328224049_associate_vm_info_with_vms_table.rb deleted file mode 100644 index ededb1d4a84..00000000000 --- a/src/bosh-director/db/migrations/director/20170328224049_associate_vm_info_with_vms_table.rb +++ /dev/null @@ -1,52 +0,0 @@ -Sequel.migration do - up do - alter_table(:instances) do - drop_foreign_key :vm_id - end - - drop_table :vms - - create_table :vms do - primary_key :id - foreign_key :instance_id, :instances, null: false - String :agent_id, unique: true - String :cid, unique: true - String :credentials_json - String :trusted_certs_sha1, {:default => ::Digest::SHA1.hexdigest('')} - end - - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table(:vms) do - set_column_type :credentials_json, 'longtext' - end - end - - alter_table(:instances) do - add_column :active_vm_id, Integer - add_foreign_key [:active_vm_id], :vms, name: :instance_vm_id_fkey, unique: true - end - - self[:instances].each do |instance| - if instance[:vm_cid] - vm_id = self[:vms].insert( - instance_id: instance[:id], - cid: instance[:vm_cid], - agent_id: instance[:agent_id], - credentials_json: instance[:credentials_json], - trusted_certs_sha1: instance[:trusted_certs_sha1], - ) - - self[:instances].where(id: instance[:id]).update( - active_vm_id: vm_id - ) - end - end - - alter_table(:instances) do - rename_column :vm_cid, :vm_cid_bak - rename_column :credentials_json, :credentials_json_bak - rename_column :agent_id, :agent_id_bak - rename_column :trusted_certs_sha1, :trusted_certs_sha1_bak - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170331171657_remove_active_vm_id_from_instances.rb b/src/bosh-director/db/migrations/director/20170331171657_remove_active_vm_id_from_instances.rb deleted file mode 100644 index a45dd4eaee7..00000000000 --- a/src/bosh-director/db/migrations/director/20170331171657_remove_active_vm_id_from_instances.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - up do - alter_table(:instances) do - drop_foreign_key :active_vm_id - end - - alter_table(:vms) do - add_column :active, TrueClass, default: false - end - - self[:vms].update(active: true) - end -end diff --git a/src/bosh-director/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables.rb b/src/bosh-director/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables.rb deleted file mode 100644 index 439a0eeb1bd..00000000000 --- a/src/bosh-director/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables.rb +++ /dev/null @@ -1,22 +0,0 @@ -Sequel.migration do - change do - db_type = self.adapter_scheme - - alter_table(:variables) do - if [:mysql2, :mysql].include?(db_type) - drop_foreign_key [:variable_set_id] - end - - drop_index([:variable_set_id, :variable_name], name: :variable_set_id_variable_name) - - if [:mysql2, :mysql].include?(db_type) - add_foreign_key [:variable_set_id], :variable_sets, :null => false, :on_delete => :cascade - end - - add_column :is_local, TrueClass, :default => true - add_column :provider_deployment, String, :default => '' - - add_index [:variable_set_id, :variable_name, :provider_deployment], :unique => true, :name => :variable_set_name_provider_idx - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name.rb b/src/bosh-director/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name.rb deleted file mode 100644 index 0963ca34dbe..00000000000 --- a/src/bosh-director/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name.rb +++ /dev/null @@ -1,42 +0,0 @@ -Sequel.migration do - up do - alter_table :local_dns_records do - drop_index(nil, name: 'name_ip_idx') - drop_column(:name) - drop_foreign_key :instance_id - end - - alter_table :local_dns_records do - add_foreign_key :instance_id, :instances, :null => true - end - - self[:local_dns_records].delete - - self[:instances].each do |instance| - begin - instance_spec_json = JSON.parse(instance[:spec_json]) - rescue - next - end - - networks_json = instance_spec_json['networks'] - if networks_json == nil - next - end - networks_json.each do |network_name, network| - begin - self[:local_dns_records] << { - instance_id: instance[:id], - instance_group: instance[:job], - az: instance[:availability_zone], - network: network_name, - deployment: self[:deployments].first(id: instance[:deployment_id])[:name], - ip: network['ip'], - } - rescue - next - end - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records.rb b/src/bosh-director/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records.rb deleted file mode 100644 index 04417ee8bb3..00000000000 --- a/src/bosh-director/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records.rb +++ /dev/null @@ -1,23 +0,0 @@ -Sequel.migration do - up do - alter_table :local_dns_records do - add_column :agent_id, String - add_column :domain, String - end - - self[:local_dns_records].each do |local_dns_record| - next if local_dns_record[:instance_id].nil? - - vm = self[:vms].where( - instance_id: local_dns_record[:instance_id], - active: true, - ).first - - next if vm.nil? - - self[:local_dns_records].where(id: local_dns_record[:id]).update( - agent_id: vm[:agent_id], - ) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170427194511_add_runtime_config_name_support.rb b/src/bosh-director/db/migrations/director/20170427194511_add_runtime_config_name_support.rb deleted file mode 100644 index 621114e732e..00000000000 --- a/src/bosh-director/db/migrations/director/20170427194511_add_runtime_config_name_support.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:runtime_configs) do - add_column :name, String, default: '', null: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170503205545_change_id_local_dns_to_bigint.rb b/src/bosh-director/db/migrations/director/20170503205545_change_id_local_dns_to_bigint.rb deleted file mode 100644 index 55a68773a9b..00000000000 --- a/src/bosh-director/db/migrations/director/20170503205545_change_id_local_dns_to_bigint.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - change do - # sqlite uses bigint for all int fields already, so skip this - # (and if we try to do this on sqlite, it breaks the primary key sequence) - next if adapter_scheme == :sqlite - - set_column_type :local_dns_records, :id, :Bignum - set_column_type :local_dns_blobs, :id, :Bignum - set_column_type :local_dns_blobs, :version, :Bignum - set_column_type :agent_dns_versions, :id, :Bignum - set_column_type :agent_dns_versions, :dns_version, :Bignum - end -end diff --git a/src/bosh-director/db/migrations/director/20170510154449_add_multi_runtime_config_support.rb b/src/bosh-director/db/migrations/director/20170510154449_add_multi_runtime_config_support.rb deleted file mode 100644 index b4af5fc2a64..00000000000 --- a/src/bosh-director/db/migrations/director/20170510154449_add_multi_runtime_config_support.rb +++ /dev/null @@ -1,19 +0,0 @@ -Sequel.migration do - change do - create_table :deployments_runtime_configs do - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - foreign_key :runtime_config_id, :runtime_configs, :null => false, :on_delete => :cascade - unique [:deployment_id, :runtime_config_id], :name => :deployment_id_runtime_config_id_unique - end - - self[:deployments].each do |deployment| - unless deployment[:runtime_config_id].nil? - self[:deployments_runtime_configs].insert(deployment_id: deployment[:id], runtime_config_id: deployment[:runtime_config_id]) - end - end - - alter_table(:deployments) do - drop_foreign_key :runtime_config_id - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170510190908_alter_ephemeral_blobs.rb b/src/bosh-director/db/migrations/director/20170510190908_alter_ephemeral_blobs.rb deleted file mode 100644 index b2f1818fa81..00000000000 --- a/src/bosh-director/db/migrations/director/20170510190908_alter_ephemeral_blobs.rb +++ /dev/null @@ -1,40 +0,0 @@ -Sequel.migration do - up do - rename_table :ephemeral_blobs, :blobs - - alter_table(:blobs) do - add_column :type, String - end - - # technically there may be some local_dns blobs in here as well, but we'll use compiled-release because it has a - # more restrictive retention policy and will clean up old entries more quickly - self[:blobs].update(type: 'compiled-release') - - rename_table :local_dns_blobs, :local_dns_blobs_old - - create_table :local_dns_blobs do - primary_key :id, :Bignum - foreign_key :blob_id, :blobs, foreign_key_constraint_name: 'local_dns_blobs_blob_id_fkey', null: false - Bignum :version, null: false - Time :created_at, null: false - end - - self[:local_dns_blobs_old].each do |blob| - self[:blobs] << { - blobstore_id: blob[:blobstore_id], - sha1: blob[:sha1], - created_at: blob[:created_at], - type: 'dns', - } - - self[:local_dns_blobs] << { - id: blob[:id], - blob_id: self[:blobs].where(blobstore_id: blob[:blobstore_id]).all[0][:id], - version: blob[:version], - created_at: blob[:created_at], - } - end - - drop_table :local_dns_blobs_old - end -end diff --git a/src/bosh-director/db/migrations/director/20170606225018_add_cpi_to_cloud_records.rb b/src/bosh-director/db/migrations/director/20170606225018_add_cpi_to_cloud_records.rb deleted file mode 100644 index e3450c10e1b..00000000000 --- a/src/bosh-director/db/migrations/director/20170606225018_add_cpi_to_cloud_records.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'yaml' - -Sequel.migration do - up do - alter_table(:orphan_disks) do - add_column :cpi, String, default: '' - end - - latest_cloud_config_query = self[:cloud_configs].where(id: self[:cloud_configs].max(:id)) - if latest_cloud_config_query.any? - begin - latest_cloud_config = YAML::load(latest_cloud_config_query.first[:properties]) - rescue YAML::SyntaxError - latest_cloud_config = {} - end - - if latest_cloud_config.has_key?('azs') - latest_cloud_config['azs'].each do |az_hash| - name = az_hash['name'] - cpi_name = az_hash['cpi'] - self[:orphan_disks].where(availability_zone: name).update(cpi: cpi_name) if cpi_name - end - end - end - - alter_table(:vms) do - add_column :cpi, String, default: '' - end - - # @todo self[].where(availability_zone != '', cpi: '').update(cpi: latest_cpi_config['cpis'][0]['name']) - - self[:vms].all.each do |vm| - instance = self[:instances].where(id: vm[:instance_id]).first - next if instance[:availability_zone].nil? - - deployment = self[:deployments].where(id: instance[:deployment_id]).first - next if deployment[:cloud_config_id].nil? - - begin - cloud_config = YAML::load(self[:cloud_configs].where(id: deployment[:cloud_config_id]).first[:properties]) - rescue YAML::SyntaxError - cloud_config = {} - end - - if cloud_config.has_key?('azs') - cloud_config['azs'].each do |az_hash| - next unless az_hash.has_key?('cpi') - next if az_hash['name'] != instance[:availability_zone] - - self[:vms].where(id: vm[:id]).update(cpi: az_hash['cpi']) - end - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170607182149_add_task_id_to_locks.rb b/src/bosh-director/db/migrations/director/20170607182149_add_task_id_to_locks.rb deleted file mode 100644 index a5543cd4162..00000000000 --- a/src/bosh-director/db/migrations/director/20170607182149_add_task_id_to_locks.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:locks) do - add_column :task_id, String, default: '', null: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170612013910_add_created_at_to_vms.rb b/src/bosh-director/db/migrations/director/20170612013910_add_created_at_to_vms.rb deleted file mode 100644 index 3ee39ce1830..00000000000 --- a/src/bosh-director/db/migrations/director/20170612013910_add_created_at_to_vms.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - change do - alter_table(:vms) do - add_column :created_at, Time - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170616173221_remove_users_table.rb b/src/bosh-director/db/migrations/director/20170616173221_remove_users_table.rb deleted file mode 100644 index 9d3ef6e9120..00000000000 --- a/src/bosh-director/db/migrations/director/20170616173221_remove_users_table.rb +++ /dev/null @@ -1,5 +0,0 @@ -Sequel.migration do - up do - drop_table :users - end -end diff --git a/src/bosh-director/db/migrations/director/20170616185237_migrate_spec_json_links.rb b/src/bosh-director/db/migrations/director/20170616185237_migrate_spec_json_links.rb deleted file mode 100644 index 6676847fb12..00000000000 --- a/src/bosh-director/db/migrations/director/20170616185237_migrate_spec_json_links.rb +++ /dev/null @@ -1,36 +0,0 @@ -Sequel.migration do - up do - self[:instances].each do |instance| - begin - instance_spec_json = JSON.parse(instance[:spec_json]) - rescue - next - end - - if !instance_spec_json['job'] - next - end - - links_hash = instance_spec_json['links'] - jobs_hash = instance_spec_json['job']['templates'] - - if links_hash == nil - next - end - - if jobs_hash == nil || jobs_hash.empty? - next - end - - instance_spec_json['links'] = {} - - jobs_hash.each do |job| - job_name = job['name'] - instance_spec_json['links'][job_name] = links_hash - end - - self[:instances].where(id: instance[:id]).update(spec_json: JSON.dump(instance_spec_json)) - - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170628221611_add_canonical_az_names_and_ids.rb b/src/bosh-director/db/migrations/director/20170628221611_add_canonical_az_names_and_ids.rb deleted file mode 100644 index 5241f07eacf..00000000000 --- a/src/bosh-director/db/migrations/director/20170628221611_add_canonical_az_names_and_ids.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - up do - create_table :local_dns_encoded_azs do - primary_key :id - String :name, unique: true, null: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170705204352_add_cpi_to_disks.rb b/src/bosh-director/db/migrations/director/20170705204352_add_cpi_to_disks.rb deleted file mode 100644 index 6fc84e98d47..00000000000 --- a/src/bosh-director/db/migrations/director/20170705204352_add_cpi_to_disks.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'yaml' - -Sequel.migration do - up do - alter_table(:persistent_disks) do - add_column :cpi, String, default: '' - end - - self[:persistent_disks].all.each do |disk| - instance = self[:instances].where(id: disk[:instance_id]).first - next if instance[:availability_zone].nil? - - deployment = self[:deployments].where(id: instance[:deployment_id]).first - next if deployment[:cloud_config_id].nil? - - begin - cloud_config = YAML::load(self[:cloud_configs].where(id: deployment[:cloud_config_id]).first[:properties]) - rescue YAML::SyntaxError - cloud_config = {} - end - - if cloud_config.has_key?('azs') - cloud_config['azs'].each do |az_hash| - next unless az_hash.has_key?('cpi') - next if az_hash['name'] != instance[:availability_zone] - - self[:persistent_disks].where(id: disk[:id]).update(cpi: az_hash['cpi']) - end - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170705211620_add_templates_json_to_templates.rb b/src/bosh-director/db/migrations/director/20170705211620_add_templates_json_to_templates.rb deleted file mode 100644 index 64db9d3eff6..00000000000 --- a/src/bosh-director/db/migrations/director/20170705211620_add_templates_json_to_templates.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - up do - adapter_scheme = self.adapter_scheme - alter_table(:templates) do - add_column :templates_json, [:mysql2, :mysql].include?(adapter_scheme) ? 'longtext' : 'text' - end - end -end - diff --git a/src/bosh-director/db/migrations/director/20170803163303_register_known_az_names.rb b/src/bosh-director/db/migrations/director/20170803163303_register_known_az_names.rb deleted file mode 100644 index 61885aed769..00000000000 --- a/src/bosh-director/db/migrations/director/20170803163303_register_known_az_names.rb +++ /dev/null @@ -1,17 +0,0 @@ -Sequel.migration do - up do - self[:instances]. - select(:availability_zone). - exclude(availability_zone: nil). - distinct. - all.each do |az_entry| - self[:local_dns_encoded_azs] << { name: az_entry[:availability_zone] } - end - - self[:local_dns_records] << { - instance_id: nil, - ip: 'flush-dns', - } if self[:local_dns_records].all.count > 0 - end -end - diff --git a/src/bosh-director/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs.rb b/src/bosh-director/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs.rb deleted file mode 100644 index 9c16013896e..00000000000 --- a/src/bosh-director/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs.rb +++ /dev/null @@ -1,18 +0,0 @@ -Sequel.migration do - up do - self[:errand_runs].delete - - adapter_scheme = self.adapter_scheme - - alter_table(:errand_runs) do - drop_foreign_key :instance_id - add_foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade, default: -1 - add_column :errand_name, [:mysql2, :mysql].include?(adapter_scheme) ? 'longtext' : 'text' - add_column :successful_state_hash, String, size: 512 - - drop_column :successful_configuration_hash - drop_column :successful_packages_spec - drop_column :successful - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170815175515_change_variable_ids_to_bigint.rb b/src/bosh-director/db/migrations/director/20170815175515_change_variable_ids_to_bigint.rb deleted file mode 100644 index 0e86035cfe4..00000000000 --- a/src/bosh-director/db/migrations/director/20170815175515_change_variable_ids_to_bigint.rb +++ /dev/null @@ -1,28 +0,0 @@ -Sequel.migration do - change do - # sqlite uses bigint for all int fields already, so skip this - # (and if we try to do this on sqlite, it breaks the primary key sequence) - next if adapter_scheme == :sqlite - - alter_table(:instances) do - drop_foreign_key [:variable_set_id], name: :instance_table_variable_set_fkey - end - alter_table(:variables) do - drop_foreign_key [:variable_set_id] - end - - set_column_type :variable_sets, :id, :Bignum - set_column_type :instances, :variable_set_id, :Bignum - set_column_type :variables, :variable_set_id, :Bignum - - alter_table(:instances) do - add_foreign_key [:variable_set_id], :variable_sets, :name=>:instance_table_variable_set_fkey - end - alter_table(:variables) do - add_foreign_key [:variable_set_id], :variable_sets, :name=>:variable_table_variable_set_fkey, :on_delete => :cascade - end - - set_column_type :variables, :id, :Bignum - - end -end diff --git a/src/bosh-director/db/migrations/director/20170821141953_remove_unused_credentials_json_columns.rb b/src/bosh-director/db/migrations/director/20170821141953_remove_unused_credentials_json_columns.rb deleted file mode 100644 index 38d2c9833bf..00000000000 --- a/src/bosh-director/db/migrations/director/20170821141953_remove_unused_credentials_json_columns.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - change do - alter_table(:instances) do - drop_column :credentials_json_bak - end - - alter_table(:vms) do - drop_column :credentials_json - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6.rb b/src/bosh-director/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6.rb deleted file mode 100644 index 1496f7c8178..00000000000 --- a/src/bosh-director/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6.rb +++ /dev/null @@ -1,25 +0,0 @@ -Sequel.migration do - change do - alter_table :ip_addresses do - add_column(:address_temp, String, unique: true) - end - - self[:ip_addresses].each do |ip_address| - self[:ip_addresses].filter(:id => ip_address[:id]).update(address_temp: ip_address[:address].to_s) - end - - alter_table :ip_addresses do - drop_column :address - rename_column :address_temp, :address_str - add_index [:address_str], unique: true, address_str: 'unique_address_str' - set_column_not_null :address_str - end - - - if [:mysql2, :mysql].include?(adapter_scheme) - alter_table :ip_addresses do - drop_index([:address_temp], name: :address_temp) - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170828174622_add_spec_json_to_templates.rb b/src/bosh-director/db/migrations/director/20170828174622_add_spec_json_to_templates.rb deleted file mode 100644 index e442ac5f633..00000000000 --- a/src/bosh-director/db/migrations/director/20170828174622_add_spec_json_to_templates.rb +++ /dev/null @@ -1,37 +0,0 @@ -Sequel.migration do - change do - alter_table(:templates) do - add_column :spec_json, String - end - - if [:mysql,:mysql2].include? adapter_scheme - set_column_type :templates, :spec_json, 'longtext' - end - - self[:templates].all do |template| - spec_hash = {} - - if JSON.load(template[:properties_json]) - spec_hash[:properties] = JSON.load(template[:properties_json]) - end - - if JSON.load(template[:consumes_json]) - spec_hash[:consumes] = JSON.load(template[:consumes_json]) - end - - if JSON.load(template[:provides_json]) - spec_hash[:provides] = JSON.load(template[:provides_json]) - end - - if JSON.load(template[:logs_json]) - spec_hash[:logs] = JSON.load(template[:logs_json]) - end - - if JSON.load(template[:templates_json]) - spec_hash[:templates] = JSON.load(template[:templates_json]) - end - - self[:templates].where(id: template[:id]).update(spec_json: JSON.dump(spec_hash)) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups.rb b/src/bosh-director/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups.rb deleted file mode 100644 index 130bac36dad..00000000000 --- a/src/bosh-director/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups.rb +++ /dev/null @@ -1,28 +0,0 @@ -Sequel.migration do - change do - create_table :local_dns_encoded_instance_groups do - primary_key :id - String :name, null: false - foreign_key :deployment_id, :deployments, null: false, on_delete: :cascade - index [:name, :deployment_id], unique: true - end - - create_table :local_dns_encoded_networks do - primary_key :id - String :name, null: false, unique: true - end - - instance_entries_query = self[:instances]. - select(select(:job).as(:name), :deployment_id). - distinct - - self[:local_dns_encoded_instance_groups].multi_insert instance_entries_query - - network_entries_query = self[:local_dns_records]. - exclude(network: nil). - select(select(:network).as(:name)). - distinct - - self[:local_dns_encoded_networks].multi_insert network_entries_query - end -end diff --git a/src/bosh-director/db/migrations/director/20171010144941_add_configs.rb b/src/bosh-director/db/migrations/director/20171010144941_add_configs.rb deleted file mode 100644 index 3c970d49fea..00000000000 --- a/src/bosh-director/db/migrations/director/20171010144941_add_configs.rb +++ /dev/null @@ -1,22 +0,0 @@ -Sequel.migration do - change do - adapter_scheme = self.adapter_scheme - - create_table :configs do - primary_key :id - - String :name, :null => false - String :type, :null => false - - if [:mysql2, :mysql].include?(adapter_scheme) - longtext :content - else - text :content - end - - Time :created_at, null: false - - TrueClass :deleted, default: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171010150659_migrate_runtime_configs.rb b/src/bosh-director/db/migrations/director/20171010150659_migrate_runtime_configs.rb deleted file mode 100644 index 75b4a268e99..00000000000 --- a/src/bosh-director/db/migrations/director/20171010150659_migrate_runtime_configs.rb +++ /dev/null @@ -1,36 +0,0 @@ -Sequel.migration do - change do - - create_table :deployments_configs do - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - foreign_key :config_id, :configs, :null => false, :on_delete => :cascade - unique [:deployment_id, :config_id], :name => :deployment_id_config_id_unique - end - - default_uuid = SecureRandom.uuid - - self[:runtime_configs].each do |runtime_config| - name = if runtime_config[:name].empty? - 'default' - elsif runtime_config[:name] == 'default' - "default-#{default_uuid}" - else - runtime_config[:name] - end - config_id = self[:configs].insert({ - type: 'runtime', - name: name, - content: runtime_config[:properties], - created_at: runtime_config[:created_at] - }) - self[:deployments_runtime_configs].where(runtime_config_id: [runtime_config[:id]]).each do |entry| - self[:deployments_configs].insert( - deployment_id: entry[:deployment_id], - config_id: config_id - ) - end - end - - drop_table :deployments_runtime_configs - end -end diff --git a/src/bosh-director/db/migrations/director/20171010161532_migrate_cloud_configs.rb b/src/bosh-director/db/migrations/director/20171010161532_migrate_cloud_configs.rb deleted file mode 100644 index 5430042443e..00000000000 --- a/src/bosh-director/db/migrations/director/20171010161532_migrate_cloud_configs.rb +++ /dev/null @@ -1,23 +0,0 @@ -Sequel.migration do - change do - self[:cloud_configs].each do |cloud_config| - config_id = self[:configs].insert({ - type: 'cloud', - name: 'default', - content: cloud_config[:properties], - created_at: cloud_config[:created_at] - }) - self[:deployments].where(cloud_config_id: cloud_config[:id]).each do |entry| - self[:deployments_configs].insert( - deployment_id: entry[:id], - config_id: config_id - ) - end - end - - alter_table(:deployments) do - drop_foreign_key :cloud_config_id - end - - end -end diff --git a/src/bosh-director/db/migrations/director/20171011122118_migrate_cpi_configs.rb b/src/bosh-director/db/migrations/director/20171011122118_migrate_cpi_configs.rb deleted file mode 100644 index 7680752850a..00000000000 --- a/src/bosh-director/db/migrations/director/20171011122118_migrate_cpi_configs.rb +++ /dev/null @@ -1,12 +0,0 @@ -Sequel.migration do - change do - self[:cpi_configs].each do |cpi_config| - self[:configs].insert({ - type: 'cpi', - name: 'default', - content: cpi_config[:properties], - created_at: cpi_config[:created_at] - }) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171018102040_remove_compilation_local_dns_records.rb b/src/bosh-director/db/migrations/director/20171018102040_remove_compilation_local_dns_records.rb deleted file mode 100644 index 6739f686a17..00000000000 --- a/src/bosh-director/db/migrations/director/20171018102040_remove_compilation_local_dns_records.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - up do - self[:local_dns_records].where( - instance_id: self[:instances] - .where(compilation: true) - .select(:id) - .collect { |i| i[:id] } - ).delete - end -end diff --git a/src/bosh-director/db/migrations/director/20171030224934_convert_nil_configs_to_empty.rb b/src/bosh-director/db/migrations/director/20171030224934_convert_nil_configs_to_empty.rb deleted file mode 100644 index 0bf37211f70..00000000000 --- a/src/bosh-director/db/migrations/director/20171030224934_convert_nil_configs_to_empty.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'yaml' - -Sequel.migration do - change do - self[:configs].each do |config| - parsed = nil - old_content = config[:content] - unless old_content.nil? - begin - parsed = YAML.load(config[:content]) - rescue - next - end - end - - if parsed.nil? - self[:configs].where(id: config[:id]).update(content: '--- {}') - end - end - - alter_table :configs do - set_column_not_null :content - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171104185823_add_manifest_text_to_deployments.rb b/src/bosh-director/db/migrations/director/20171104185823_add_manifest_text_to_deployments.rb deleted file mode 100644 index 1bc09afc518..00000000000 --- a/src/bosh-director/db/migrations/director/20171104185823_add_manifest_text_to_deployments.rb +++ /dev/null @@ -1,14 +0,0 @@ -Sequel.migration do - change do - adapter_scheme = self.adapter_scheme - alter_table(:deployments) do - add_column :manifest_text, [:mysql2, :mysql].include?(adapter_scheme) ? 'longtext' : 'text' - end - - self[:deployments].all do |deployment| - if deployment[:manifest_text].nil? || deployment[:manifest_text].empty? - self[:deployments].where(id: deployment[:id]).update(manifest_text: deployment[:manifest] || '{}') - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171113000000_add_links_api.rb b/src/bosh-director/db/migrations/director/20171113000000_add_links_api.rb deleted file mode 100644 index 87c05679bd9..00000000000 --- a/src/bosh-director/db/migrations/director/20171113000000_add_links_api.rb +++ /dev/null @@ -1,209 +0,0 @@ -Sequel.migration do - up do - create_table :link_providers do - primary_key :id - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - String :instance_group, :null => false - String :name, :null => false - String :type, :null => false - Integer :serial_id - end - - alter_table(:link_providers) do - add_index [:deployment_id, :instance_group, :name, :type], unique: true, name: 'link_providers_constraint' - end - - create_table :link_provider_intents do - primary_key :id - foreign_key :link_provider_id, :link_providers, :on_delete => :cascade - String :original_name, :null => false - String :type, :null => false - String :name # This should never be null, but... because when we find/create we don't use it as a constraint and it can be updated at any moment.. We can't enforce it to start off as non-null. - String :content # rely on networks, make optional because of delayed content resolution - Boolean :shared, :null => false, :default => false - Boolean :consumable, :null => false, :default => true - String :metadata #mapped properties - Integer :serial_id - end - - alter_table(:link_provider_intents) do - add_index [:link_provider_id, :original_name], unique: true, name: 'link_provider_intents_constraint' - end - - create_table :link_consumers do - primary_key :id - foreign_key :deployment_id, :deployments, :on_delete => :cascade - String :instance_group - String :name, :null => false - String :type, :null => false - Integer :serial_id - end - - alter_table(:link_consumers) do - add_index [:deployment_id, :instance_group, :name, :type], unique: true, name: 'link_consumers_constraint' - end - - create_table :link_consumer_intents do - primary_key :id - foreign_key :link_consumer_id, :link_consumers, :on_delete => :cascade - String :original_name, :null => false - String :type, :null => false - String :name # This should never be null, but... because when we find/create we don't use it as a constraint and it can be updated at any moment.. We can't enforce it to start off as non-null. - Boolean :optional, :null => false, :default => false - Boolean :blocked, :null => false, :default => false # intentionally blocking the consumption of the link, consume: nil - String :metadata # put extra json object that has some flags, ip addresses true or false, network, from_deployment or any other potential thing - Integer :serial_id - end - - alter_table(:link_consumer_intents) do - add_index [:link_consumer_id, :original_name], unique: true, name: 'link_consumer_intents_constraint' - end - - create_table :links do - primary_key :id - foreign_key :link_provider_intent_id, :link_provider_intents, :on_delete => :set_null - foreign_key :link_consumer_intent_id, :link_consumer_intents, :on_delete => :cascade, :null => false - String :name, :null => false - String :link_content - Time :created_at - end - - create_table :instances_links do - primary_key :id - foreign_key :link_id, :links, :on_delete => :cascade, :null => false - foreign_key :instance_id, :instances, :on_delete => :cascade, :null => false - Integer :serial_id - end - - alter_table(:instances_links) do - add_index [:link_id, :instance_id], unique: true, name: 'instances_links_constraint' - end - - alter_table(:deployments) do - add_column :has_stale_errand_links, 'boolean', null: false, default: false - end - - if [:mysql, :mysql2].include? adapter_scheme - set_column_type :link_provider_intents, :content, 'longtext' - set_column_type :links, :link_content, 'longtext' - end - - self[:deployments].each do |deployment| - link_spec_json = JSON.parse(deployment[:link_spec_json] || '{}') - link_spec_json.each do |instance_group_name, provider_jobs| - provider_jobs.each do |provider_job_name, link_names| - provider_id = self[:link_providers].insert({ - deployment_id: deployment[:id], - name: provider_job_name, - type: 'job', - instance_group: instance_group_name, - serial_id: 0, - }) - - link_names.each do |link_name, link_types| - link_types.each do |link_type, content| - self[:link_provider_intents].insert( - { - link_provider_id: provider_id, - original_name: link_name, - type: link_type, - name: link_name, - shared: true, - consumable: true, - content: content.to_json, - serial_id: 0, - } - ) - end - end - end - end - end - - self[:deployments].update(has_stale_errand_links: true) - - links_to_migrate = {} - - Struct.new('LinkKey', :deployment_id, :instance_group, :job, :link_name) unless defined?(Struct::LinkKey) - Struct.new('LinkDetail', :link_id, :content) unless defined?(Struct::LinkDetail) - - self[:instances].each do |instance| - spec_json = JSON.parse(instance[:spec_json] || '{}') - links = spec_json.delete('links') || {} - links.each do |job_name, consumed_links| - consumer = self[:link_consumers].where(deployment_id: instance[:deployment_id], instance_group: instance[:job], name: job_name).first - - if consumer - consumer_id = consumer[:id] - else - consumer_id = self[:link_consumers].insert( - { - deployment_id: instance[:deployment_id], - instance_group: instance[:job], - name: job_name, - type: 'job', - serial_id: 0, - } - ) - end - - consumed_links.each do |link_name, link_data| - link_key = Struct::LinkKey.new(instance[:deployment_id], instance[:job], job_name, link_name) - - # since we can go through multiple instances - link_details = links_to_migrate[link_key] || [] - link_detail = link_details.find do |link_detail| - link_detail.content == link_data - end - - link_consumer_intent = self[:link_consumer_intents].where(link_consumer_id: consumer_id, original_name: link_name).first - - if link_consumer_intent - link_consumer_intent_id = link_consumer_intent[:id] - else - # #153608828 set original name and alias to the same value (link_name from consumed_links) - link_consumer_intent_id = self[:link_consumer_intents].insert( - { - link_consumer_id: consumer_id, - original_name: link_name, - name: link_name, - type: 'undefined-migration', - optional: false, - blocked: false, - serial_id: 0 - } - ) - end - - unless link_detail - link_id = self[:links].insert( - { - name: link_name, - link_provider_intent_id: nil, - link_consumer_intent_id: link_consumer_intent_id, - link_content: link_data.to_json, - created_at: Time.now, - } - ) - link_detail = Struct::LinkDetail.new(link_id, link_data) - - link_details << link_detail - links_to_migrate[link_key] = link_details - end - - self[:instances_links] << { - link_id: link_detail.link_id, - instance_id: instance[:id], - serial_id: 0, - } - end - end - self[:instances].where(id: instance[:id]).update(spec_json: JSON.dump(spec_json)) - end - - alter_table(:deployments) do - drop_column :link_spec_json - add_column :links_serial_id, Integer, default: 0 - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171117230219_add_network_spec_to_vms.rb b/src/bosh-director/db/migrations/director/20171117230219_add_network_spec_to_vms.rb deleted file mode 100644 index 7c7b77594d8..00000000000 --- a/src/bosh-director/db/migrations/director/20171117230219_add_network_spec_to_vms.rb +++ /dev/null @@ -1,20 +0,0 @@ -Sequel.migration do - up do - column_type = String - if [:mysql2, :mysql].include?(adapter_scheme) - column_type = 'longtext' - end - - alter_table(:vms) do - add_column(:network_spec_json, column_type) - end - - self[:vms].all do |vm| - if vm[:active] == true - instance = self[:instances].where(id: vm[:instance_id]).first - instance_spec = JSON.parse(instance[:spec_json]) - self[:vms].where(id: vm[:id]).update(network_spec_json: JSON.dump(instance_spec['networks'])) - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20171201153629_remove_unused_template_columns.rb b/src/bosh-director/db/migrations/director/20171201153629_remove_unused_template_columns.rb deleted file mode 100644 index c50ff3fba99..00000000000 --- a/src/bosh-director/db/migrations/director/20171201153629_remove_unused_template_columns.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - up do - alter_table(:templates) do - drop_column :provides_json - drop_column :consumes_json - drop_column :properties_json - drop_column :logs_json - drop_column :templates_json - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180119183014_add_stemcell_matches.rb b/src/bosh-director/db/migrations/director/20180119183014_add_stemcell_matches.rb deleted file mode 100644 index bc3321da256..00000000000 --- a/src/bosh-director/db/migrations/director/20180119183014_add_stemcell_matches.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - up do - create_table(:stemcell_matches) do - primary_key :id - String :name - String :version - String :cpi - unique [:name, :version, :cpi] - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses.rb b/src/bosh-director/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses.rb deleted file mode 100644 index 349dd9edbe9..00000000000 --- a/src/bosh-director/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses.rb +++ /dev/null @@ -1,14 +0,0 @@ -Sequel.migration do - up do - alter_table(:ip_addresses) do - add_foreign_key :vm_id, :vms, null: true - end - - self[:vms].all do |vm| - if vm[:active] == true - instance = self[:instances].where(id: vm[:instance_id]).first - self[:ip_addresses].where(instance_id: instance[:id]).update(vm_id: vm[:id]) - end - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads.rb b/src/bosh-director/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads.rb deleted file mode 100644 index 317102de251..00000000000 --- a/src/bosh-director/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads.rb +++ /dev/null @@ -1,5 +0,0 @@ -Sequel.migration do - up do - rename_table :stemcell_matches, :stemcell_uploads - end -end diff --git a/src/bosh-director/db/migrations/director/20180130182845_add_team_id_to_configs.rb b/src/bosh-director/db/migrations/director/20180130182845_add_team_id_to_configs.rb deleted file mode 100644 index 76869385ecb..00000000000 --- a/src/bosh-director/db/migrations/director/20180130182845_add_team_id_to_configs.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:configs) do - add_column :team_id, Integer - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180203000738_create_orphaned_vms.rb b/src/bosh-director/db/migrations/director/20180203000738_create_orphaned_vms.rb deleted file mode 100644 index 33c33c5e51f..00000000000 --- a/src/bosh-director/db/migrations/director/20180203000738_create_orphaned_vms.rb +++ /dev/null @@ -1,23 +0,0 @@ -Sequel.migration do - up do - adapter_scheme = self.adapter_scheme - - alter_table :ip_addresses do - add_column :orphaned_vm_id, Integer - end - - create_table :orphaned_vms do - primary_key :id - String :cid, null: false - Integer :instance_id, null: false - String :availability_zone - if %i[mysql2 mysql].include?(adapter_scheme) - longtext :cloud_properties - else - text :cloud_properties - end - String :cpi - Time :orphaned_at, null: false - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180215152554_add_api_version_to_stemcells.rb b/src/bosh-director/db/migrations/director/20180215152554_add_api_version_to_stemcells.rb deleted file mode 100644 index 97f471e2226..00000000000 --- a/src/bosh-director/db/migrations/director/20180215152554_add_api_version_to_stemcells.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:stemcells) do - add_column :api_version, Integer - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms.rb b/src/bosh-director/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms.rb deleted file mode 100644 index fbc3460d961..00000000000 --- a/src/bosh-director/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - up do - alter_table(:vms) do - add_column :stemcell_api_version, Integer, null: true - end - - alter_table(:orphaned_vms) do - add_column :stemcell_api_version, Integer, null: true - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms.rb b/src/bosh-director/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms.rb deleted file mode 100644 index 56c193f188e..00000000000 --- a/src/bosh-director/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:orphaned_vms) do - drop_column :instance_id - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180410180821_migrate_legacy_update_strategy.rb b/src/bosh-director/db/migrations/director/20180410180821_migrate_legacy_update_strategy.rb deleted file mode 100644 index 8b61d75025b..00000000000 --- a/src/bosh-director/db/migrations/director/20180410180821_migrate_legacy_update_strategy.rb +++ /dev/null @@ -1,21 +0,0 @@ -Sequel.migration do - up do - self[:instances].each do |instance| - begin - instance_spec_json = JSON.parse(instance[:spec_json]) - rescue - next - end - - next if instance_spec_json['update'].nil? - - if instance_spec_json['update']['strategy'] == 'legacy' - instance_spec_json['update']['strategy'] = 'delete-create' - elsif instance_spec_json['update']['strategy'] == 'hot-swap' - instance_spec_json['update']['strategy'] = 'create-swap-delete' - end - - self[:instances].where(id: instance[:id]).update(spec_json: JSON.dump(instance_spec_json)) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy.rb b/src/bosh-director/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy.rb deleted file mode 100644 index e24c5853696..00000000000 --- a/src/bosh-director/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy.rb +++ /dev/null @@ -1,17 +0,0 @@ -Sequel.migration do - up do - self[:instances].each do |instance| - begin - instance_spec_json = JSON.parse(instance[:spec_json]) - rescue - next - end - - next if instance_spec_json['update'].nil? - - instance_spec_json['update']['vm_strategy'] = instance_spec_json['update'].delete('strategy') - - self[:instances].where(id: instance[:id]).update(spec_json: JSON.dump(instance_spec_json)) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms.rb b/src/bosh-director/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms.rb deleted file mode 100644 index bd36705a763..00000000000 --- a/src/bosh-director/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - up do - alter_table(:orphaned_vms) do - add_column :deployment_name, String - add_column :instance_name, String - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180515204145_add_vm_metadata_spec.rb b/src/bosh-director/db/migrations/director/20180515204145_add_vm_metadata_spec.rb deleted file mode 100644 index 1108c2f3794..00000000000 --- a/src/bosh-director/db/migrations/director/20180515204145_add_vm_metadata_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'json' - -Sequel.migration do - up do - json_column_type = String - json_column_type = 'longtext' if %I[mysql2 mysql].include?(adapter_scheme) - - alter_table(:vms) do - add_column(:stemcell_name, String) - add_column(:stemcell_version, String) - add_column(:env_json, json_column_type) - add_column(:cloud_properties_json, json_column_type) - end - - self[:vms].all do |vm| - instance = self[:instances].where(id: vm[:instance_id]).first - raw_spec_json = String(instance[:spec_json]) - spec_json = JSON.parse(raw_spec_json == '' ? '{}' : raw_spec_json) - if spec_json['stemcells'] - stemcell_name = String(spec_json['stemcells']['name']) - stemcell_version = String(spec_json['stemcells']['version']) - end - cloud_properties_hash = Hash(spec_json['vm_type']['cloud_properties']) if spec_json['vm_type'] - - self[:vms].where(id: vm[:id]).update( - stemcell_name: stemcell_name, - stemcell_version: stemcell_version, - env_json: Hash(spec_json['env']).to_json, - cloud_properties_json: cloud_properties_hash.to_json, - ) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180613190204_links_api_longtext_support.rb b/src/bosh-director/db/migrations/director/20180613190204_links_api_longtext_support.rb deleted file mode 100644 index a1758bc77a0..00000000000 --- a/src/bosh-director/db/migrations/director/20180613190204_links_api_longtext_support.rb +++ /dev/null @@ -1,8 +0,0 @@ -Sequel.migration do - up do - if %i[mysql mysql2].include? adapter_scheme - set_column_type :link_provider_intents, :metadata, 'longtext' - set_column_type :link_consumer_intents, :metadata, 'longtext' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20180822230006_create_network_table.rb b/src/bosh-director/db/migrations/director/20180822230006_create_network_table.rb deleted file mode 100644 index 085761e38d7..00000000000 --- a/src/bosh-director/db/migrations/director/20180822230006_create_network_table.rb +++ /dev/null @@ -1,32 +0,0 @@ -Sequel.migration do - # Create the three tables required for bosh managed networks - change do - create_table :networks do - primary_key :id - String :name, null: false - String :type, null: false - Time :created_at, null: false - Boolean :orphaned, :default => false - Time :orphaned_at - index :name, unique: true - end - - create_table :subnets do - primary_key :id - String :cid, null: false - String :name, null: false - String :range - String :gateway - String :reserved - String :cloud_properties - String :cpi, :default => '' - foreign_key :network_id, :networks, :null => false, :on_delete => :cascade - end - - create_table :deployments_networks do - foreign_key :deployment_id, :deployments, :null => false, :on_delete => :cascade - foreign_key :network_id, :networks, :null => false, :on_delete => :cascade - unique [:deployment_id, :network_id], :name => :deployment_id_network_id_unique - end - end -end \ No newline at end of file diff --git a/src/bosh-director/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group.rb b/src/bosh-director/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group.rb deleted file mode 100644 index bb78ae12089..00000000000 --- a/src/bosh-director/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group.rb +++ /dev/null @@ -1,10 +0,0 @@ -Sequel.migration do - up do - alter_table :local_dns_encoded_instance_groups do - add_column :type, String, null: false, default: 'instance-group' - drop_index %i[name deployment_id] - add_index %i[name type deployment_id], unique: true - set_column_default :type, 'instance-group' - end - end -end diff --git a/src/bosh-director/db/migrations/director/20181017233927_add_links_json_to_local_dns_record.rb b/src/bosh-director/db/migrations/director/20181017233927_add_links_json_to_local_dns_record.rb deleted file mode 100644 index b065591e80d..00000000000 --- a/src/bosh-director/db/migrations/director/20181017233927_add_links_json_to_local_dns_record.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - up do - alter_table :local_dns_records do - add_column :links_json, String, text: true - end - - set_column_type :local_dns_records, :links_json, 'longtext' if %i[mysql2 mysql].include?(adapter_scheme) - end -end diff --git a/src/bosh-director/db/migrations/director/20181019225226_rename_table_local_dns_encoded_instance_group.rb b/src/bosh-director/db/migrations/director/20181019225226_rename_table_local_dns_encoded_instance_group.rb deleted file mode 100644 index be17d99006b..00000000000 --- a/src/bosh-director/db/migrations/director/20181019225226_rename_table_local_dns_encoded_instance_group.rb +++ /dev/null @@ -1,5 +0,0 @@ -Sequel.migration do - up do - rename_table :local_dns_encoded_instance_groups, :local_dns_encoded_groups - end -end diff --git a/src/bosh-director/db/migrations/director/20190104135624_add_update_completed_to_release_versions.rb b/src/bosh-director/db/migrations/director/20190104135624_add_update_completed_to_release_versions.rb deleted file mode 100644 index fc662885806..00000000000 --- a/src/bosh-director/db/migrations/director/20190104135624_add_update_completed_to_release_versions.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - change do - alter_table(:release_versions) do - add_column :update_completed, 'boolean', null: false, default: false - end - - self[:release_versions].update(update_completed: true) - end -end diff --git a/src/bosh-director/db/migrations/director/20190114153103_add_index_to_tasks.rb b/src/bosh-director/db/migrations/director/20190114153103_add_index_to_tasks.rb deleted file mode 100644 index 506382da45f..00000000000 --- a/src/bosh-director/db/migrations/director/20190114153103_add_index_to_tasks.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table :tasks do - add_index :type - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs.rb deleted file mode 100644 index fde2087b1e0..00000000000 --- a/src/bosh-director/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs.rb +++ /dev/null @@ -1,9 +0,0 @@ -Sequel.migration do - up do - alter_table(:local_dns_blobs) do - set_column_allow_null(:blob_id) - set_column_allow_null(:version) - set_column_allow_null(:created_at) - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs.rb deleted file mode 100644 index 7e97503d2af..00000000000 --- a/src/bosh-director/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:local_dns_blobs) do - add_column :records_version, Integer, null: false, default: 0 - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190314192454_create_local_dns_aliases.rb b/src/bosh-director/db/migrations/director/20190314192454_create_local_dns_aliases.rb deleted file mode 100644 index 57bec82b1c6..00000000000 --- a/src/bosh-director/db/migrations/director/20190314192454_create_local_dns_aliases.rb +++ /dev/null @@ -1,11 +0,0 @@ -Sequel.migration do - up do - create_table :local_dns_aliases do - primary_key :id - foreign_key :deployment_id, :deployments, on_delete: :cascade - - String :domain - String :target - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs.rb b/src/bosh-director/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs.rb deleted file mode 100644 index fda297ce6e5..00000000000 --- a/src/bosh-director/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:local_dns_blobs) do - add_column :aliases_version, Integer, null: false, default: 0 - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases.rb b/src/bosh-director/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases.rb deleted file mode 100644 index 628b713b9be..00000000000 --- a/src/bosh-director/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - up do - alter_table(:local_dns_aliases) do - drop_column :target - - add_column :health_filter, String - add_column :initial_health_check, String - add_column :group_id, String - - add_column :placeholder_type, String - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190325095716_remove_resurrection_paused.rb b/src/bosh-director/db/migrations/director/20190325095716_remove_resurrection_paused.rb deleted file mode 100644 index 451aa964e5b..00000000000 --- a/src/bosh-director/db/migrations/director/20190325095716_remove_resurrection_paused.rb +++ /dev/null @@ -1,7 +0,0 @@ -Sequel.migration do - up do - alter_table(:instances) do - drop_column :resurrection_paused - end - end -end diff --git a/src/bosh-director/db/migrations/director/20190327222054_scale_dns_blob_version.rb b/src/bosh-director/db/migrations/director/20190327222054_scale_dns_blob_version.rb deleted file mode 100644 index 8f42fa8f2f3..00000000000 --- a/src/bosh-director/db/migrations/director/20190327222054_scale_dns_blob_version.rb +++ /dev/null @@ -1,13 +0,0 @@ -Sequel.migration do - up do - max_id = self[:local_dns_blobs].max(:id) - max_version = self[:local_dns_blobs].max(:version) - next if max_id.nil? || max_version.nil? - - (max_version - max_id).times do - self[:local_dns_blobs] << {} - end - - self[:local_dns_blobs].where { id > max_id }.delete - end -end diff --git a/src/bosh-director/db/migrations/migration_digests.json b/src/bosh-director/db/migrations/migration_digests.json deleted file mode 100644 index 49e9efefeb9..00000000000 --- a/src/bosh-director/db/migrations/migration_digests.json +++ /dev/null @@ -1,164 +0,0 @@ -{ - "20110209010747_initial": "b6076a08025a78eb91b1442474953a854342747e", - "20180203000738_create_orphaned_vms": "28c509f06a8d6194cfa3bc11dc1e9f4beb0f0d56", - "20110406055800_add_task_user": "704354c16a54bf02700a5d6ddd481c5030cbff39", - "20110518225809_remove_cid_constrain": "6de40662576d96f7167e1a27f1ff2944ffd51c22", - "20110617211923_add_deployments_release_versions": "c98c84f1277d9861380ec8a6cb70b13bb147f73c", - "20110622212607_add_task_checkpoint_timestamp": "204357dd1e9934bf10335baffc836f8d7cc4e4fc", - "20110628023039_add_state_to_instances": "24f51f4408ff599a717db3bfa2d2267879e579fd", - "20110709012332_add_disk_size_to_instances": "19b7d5fc900d2fa243a5f9be99cbc439a9f3a82a", - "20110906183441_add_log_bundles": "ded5a84ad0f56fef1420d8cda85e3a6b3f0a2683", - "20110907194830_add_logs_json_to_templates": "036ebb3075f90ce52c796e30eca1dcc952bafbfb", - "20110915205610_add_persistent_disks": "d33dcb2a62e13b868cbeb26693663ac4bbb3e059", - "20111005180929_add_properties": "1dfe8f3d088207786ea0065270a4994ed4720358", - "20111110024617_add_deployment_problems": "45ca090eba833c6807dc4fee242cfe83cf8ddae3", - "20111216214145_recreate_support_for_vms": "c45eb5bf675aa10629df26fe6c699ff37b54f5b5", - "20120102084027_add_credentials_to_vms": "bd885eac537cc1b31e43a70028300ff7be5f82a6", - "20120427235217_allow_multiple_releases_per_deployment": "816126d5e00abeb5a6ab07ea89d3d91e0c35a45b", - "20120524175805_add_task_type": "e10d2dda97209ad1c6a649b4f6c281ee434a7c3a", - "20120614001930_delete_redundant_deployment_release_relation": "d54bcd3cd6d69ad70fbabc1dd435cc9c5c4af32c", - "20120822004528_add_fingerprint_to_templates_and_packages": "842bfc05198064c6760cda1325a1b2df52eb18c5", - "20120830191244_add_properties_to_templates": "7e45571de3e3dd64920b1ede4b114f748ba31e6c", - "20121106190739_persist_vm_env": "ed6e52bec87a8bcd741b8c36db2b37b705601f46", - "20130222232131_add_sha1_to_stemcells": "8a9ce4b30efbede58db238c29648ecddad8b9974", - "20130312211407_add_commit_hash_to_release_versions": "9f96f31c61fdbbe2b7d1744ccb9d7eed0d7aee80", - "20130409235338_snapshot": "662c0ae2a6268576fe2a2ebd97d3ebb6edc96c8f", - "20130530164918_add_paused_flag_to_instance": "63f0e679a4ec55a83b33278b993b4a1f8c8c1b9b", - "20130531172604_add_director_attributes": "9dd58aa603d81e503931e82b767b9032b1212cfd", - "20131121182231_add_rendered_templates_archives": "24302594e5e03a2574315b29e746033f1ec58a5b", - "20131125232201_rename_rendered_templates_archives_blob_id_and_checksum_columns": "fa1adb81afccb0972136e3af1c7b777461ea02d8", - "20140116002324_pivot_director_attributes": "ba697daa864074bcae7c61fd4a62f8ebcbd68f51", - "20140124225348_proper_pk_for_attributes": "0a9acddd5330c126e1a56794529a0b88db794a0a", - "20140731215410_increase_text_limit_for_data_columns": "1b7fc9a526a7644f3860aee263dd48ac1e426d74", - "20141204234517_add_cloud_properties_to_persistent_disk": "9e20c1afd2c17e9cbe86b48a5f22b923e29873b5", - "20150102234124_denormalize_task_user_id_to_task_username": "4da0601d263534d383ca99d7e9496b4bf2a41ab2", - "20150223222605_increase_manifest_text_limit": "94d5220ab5325e3dd3c948ec84f5f1e49a8d1a68", - "20150224193313_use_larger_text_types": "6ea8b819ea7082adcd62dbbe7ef36edc308ef7fa", - "20150331002413_add_cloud_configs": "261627c074ac928acbf2302957452c062b15fd1c", - "20150401184803_add_cloud_config_to_deployments": "acff3b61dac234416f18b4bc766e55ccd9bfebc4", - "20150513225143_ip_addresses": "21c5a4948241c51c1f6c803ccb315102911fa84c", - "20150611193110_add_trusted_certs_sha1_to_vms": "b74c24a39d93f5917f0e0ae22e9c2b80e9322513", - "20150619135210_add_os_name_and_version_to_stemcells": "20db7142ae236baf0e95707df3a35b8540be70a9", - "20150702004608_add_links": "00840fcad3839e844aabc1b4dac27ef1731d416e", - "20150708231924_add_link_spec": "335894f04d0e8f5598dda3a74a7199ad617d7125", - "20150716170926_allow_null_on_blobstore_id_and_sha1_on_package": "9353f15f77981ba6e1aa9ec6bd9679c5427a8de2", - "20150724183256_add_debugging_to_ip_addresses": "4af82432fc9c00501917bf9fdfff8fda88850daf", - "20150730225029_add_uuid_to_instances": "bc3220ba4c10558ee5d56f5f6f1c08aa74cbfda1", - "20150803215805_add_availabililty_zone_and_cloud_properties_to_instances": "991c480bc36de710d180c5d4072735f96e91bd4b", - "20150804211419_add_compilation_flag_to_instance": "4495720c8d6beab2264ebce785ed9e8ebeb42f6d", - "20150918003455_add_bootstrap_node_to_instance": "52c78f3871c69203a0e76225571329f4aeec360a", - "20151008232214_add_dns_records": "6112cbe8b963dbd73087563a265d85e19de112da", - "20151015172551_add_orphan_disks_and_snapshots": "0ffc392879b37fd734c1e22d7e8867d3a5997fcd", - "20151030222853_add_templates_to_instance": "ceebfd7083bb0058957324670d9787b3a86ac99d", - "20151031001039_add_spec_to_instance": "8a2bdddf468eb3455fefc7f9f7b3106544e4fee2", - "20151109190602_rename_orphan_columns": "9fee03abdb63c77cf3a0a03dc77fa8c9fd30af4e", - "20151223172000_rename_requires_json": "73bd663eab85b60c60be8e2a663944469e6f259a", - "20151229184742_add_vm_attributes_to_instance": "a713ed392588eebf3f7679ea20f9472954dd202f", - "20160106162749_runtime_configs": "585d0d624eea9c9e2010bd1f95fe72fb753e7d7f", - "20160106163433_add_runtime_configs_to_deployments": "40d2fc2dbc10a53a302fcb83348d5c41da4c7d6a", - "20160108191637_drop_vm_env_json_from_instance": "ec39a361ee911fbb5d199e3af6a373fa6434a674", - "20160121003800_drop_vms_fkeys": "ce253162e147c2ddb131894d89ec87edffa85225", - "20160202162216_add_post_start_completed_to_instance": "c896605d5206107ac66a4cf8c439bc38e797531e", - "20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version": "4a9dc3f928d3dc187ca53d462f06ef89117183d3", - "20160211174110_add_events": "f597116fa3255af67be339189c80aff6a96ea16d", - "20160211193904_add_scopes_to_deployment": "67529d87df937a027f88dcc39f13e5a7e6731315", - "20160219175840_add_column_teams_to_deployments": "d043cd84c50ee5c5f561db48df021860f5e0e8c9", - "20160224222508_add_deployment_name_to_task": "88b064fa97cd61baece2f4ffddc713710cc6ad81", - "20160225182206_rename_post_start_completed": "fea9b108ebf49a7f1dfb27710d368c9f3f704c18", - "20160324181932_create_delayed_jobs": "108618cf9410702773645a2e09e4910eea4be8a9", - "20160324182211_add_locks": "f7d3726bec9955e7ddf34d53e6f8859c3adda1bf", - "20160329201256_set_instances_with_nil_serial_to_false": "4bf2b5d875ea2a6d2e5a998f5fd68bbdeff2f242", - "20160331225404_backfill_stemcell_os": "4dea371d37db9e96992e709b12474ca7d5b8b66f", - "20160411104407_add_task_started_at": "453bebe2cbdef72b28d4ece84423cf758ba7a0c7", - "20160414183654_set_teams_on_task": "0a0dfb6699fd5379cfa8647246ef362ca5bfd74c", - "20160427164345_add_teams": "3a591dbc8fbabc39d55a6e8d5072207ab7eef71c", - "20160511191928_ephemeral_blobs": "f761dac1b34567f06529fdf764c6c264035d4a38", - "20160513102035_add_tracking_to_instance": "e712debb89ecac9015b077a1857a2703097e8565", - "20160531164756_add_local_dns_blobs": "6a0d55115422f061370a831a198d66b93eb44b55", - "20160614182106_change_text_to_longtext_for_mysql": "073ac2b34cfc577b5e290a2d2bb7de6acbabb04f", - "20160615192201_change_text_to_longtext_for_mysql_for_additional_fields": "cf55d9e1a65cdbc77306e1c7d583247ad98d5f30", - "20160706131605_change_events_id_type": "31e4e01fd1f7ccdfb3c4c2b12a479c25809ffe33", - "20160708234509_add_local_dns_records": "8e11ce4ea48765c0b769d44ce762235bccb8c29a", - "20160712171230_add_version_to_local_dns_blobs": "94d06e693044fd6aef32cc33ccae9ce74f63f678", - "20160725090007_add_cpi_configs": "77e8258fba8d1ea297fdad4cbcc7379de7c78180", - "20160803151600_add_name_to_persistent_disks": "7d07242c22367dd885edc0182a012e4e491c5e8a", - "20160817135953_add_cpi_to_stemcells": "86c07f145372c4394725c0d5d225d45f31ad54bc", - "20160818112257_change_stemcell_unique_key": "990754d5d2363f1abd5a17e791f709bed13bdc89", - "20161031204534_populate_lifecycle_on_instance_spec": "77d0bc69b8ebc1159cf3beafdaf73c9e659cb0f2", - "20161128181900_add_logs_to_tasks": "d91e2a137fe9759de57a947337c78e317d387b81", - "20161209104649_add_context_id_to_tasks": "cab77fbee73f1e377a11e15375db83f38ea668fa", - "20161221151107_allow_null_instance_id_local_dns": "0c6c941569a2312587019c2a84b0bbe7c34e624e", - "20170104003158_add_agent_dns_version": "1765c0f5e9b2cb38c09089b615fedc4d012a5850", - "20170116235940_add_errand_runs": "1e6f5be83715dba65339a4aeb93d9d323be0901f", - "20170119202003_update_sha1_column_sizes": "bb36259d38be67c1748ec25207f44fe163281ba4", - "20170203212124_add_variables": "904a1c780a1a35b13d35dddc4f1fcf30f45cfdd8", - "20170216194502_remove_blobstore_id_idx_from_local_dns_blobs": "24a882cb8c016867d633a7396636631cd2d737d0", - "20170217000000_variables_instance_table_foreign_key_update": "6f586bcfe0017d410d2d0daafc8e01a1dbe37be2", - "20170301192646_add_deployed_successfully_to_variable_sets": "34b45e27dd813a6e91ac074b7beadbd520eda7ac", - "20170303175054_expand_template_json_column_lengths": "bb1868c23d48020990e23b25a8c5fcb1f93eb6fc", - "20170306215659_expand_vms_json_column_lengths": "544410b869c44f6af0f748cf74da4e12f1919289", - "20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records": "0a5296c0d3de35d3c3921e2f36c124f56a0a7e94", - "20170321151400_add_writable_to_variable_set": "b4a4ab1ce8b4788402cd5b55dff5a1c05d621dc9", - "20170328224049_associate_vm_info_with_vms_table": "1505f623daaff23f2190fb52b8476c6fe4d89f48", - "20170331171657_remove_active_vm_id_from_instances": "9e640563feef3e437c6ba7a5f289927488a2292a", - "20170405144414_add_cross_deployment_links_support_for_variables": "457fcff2c0ae0cdc1c2da694d58e2b4bc39735c3", - "20170405181126_backfill_local_dns_records_and_drop_name": "3532272ca024a2047287f40573a5ae48b9ada065", - "20170412205032_add_agent_id_and_domain_name_to_local_dns_records": "3391eb9ece5a0f1d91c406806a2df96ec45d39b9", - "20170427194511_add_runtime_config_name_support": "24c478772418b06bbe408c6a8ad098738ff1c621", - "20170503205545_change_id_local_dns_to_bigint": "6ba202be7ca0cb81e16fd2c82a50a03dbada30e4", - "20170510154449_add_multi_runtime_config_support": "5f439c8810fdce14e19cb245923a6909370381d5", - "20170510190908_alter_ephemeral_blobs": "b795a90e2a23f6df7081dbaa210de60919a44b09", - "20170606225018_add_cpi_to_cloud_records": "e792f59a1d71d66fa7e02e6d5265e4e31364abea", - "20170607182149_add_task_id_to_locks": "226cef42c81d5cee602f091a0bc184c57c2bc628", - "20170612013910_add_created_at_to_vms": "84568dc1e4f09653e53bcfa2ff071d70ac9b6fd4", - "20170616173221_remove_users_table": "5f35086a0f65d81477731b7995fd933a10c9299e", - "20170616185237_migrate_spec_json_links": "bd36243e6583c7a9c925e44ddbf27b2aa1ef54ed", - "20170628221611_add_canonical_az_names_and_ids": "a75f52e04ad63156fd43861f1f7849ea76029fa1", - "20170705204352_add_cpi_to_disks": "047e88df8dbe6cc449d675472bb4f838d8e6e85e", - "20170705211620_add_templates_json_to_templates": "ed9969aab2493052530e36d012cd892948641f2c", - "20170803163303_register_known_az_names": "51ab548d8187c75a1a7dff34861f658dfc11dae9", - "20170804191205_add_deployment_and_errand_name_to_errand_runs": "4429f1e811e064c236ee4c32b3964992ec7004e5", - "20170815175515_change_variable_ids_to_bigint": "e41b6c4f43c71574ed39aac43007e1f59e692273", - "20170821141953_remove_unused_credentials_json_columns": "0daf4d1363029304fc84d0df7b7b69fa04713e37", - "20170825141953_change_address_to_be_string_for_ipv6": "7807ac7e3e692d54c091421836bcaac826ae86e9", - "20170828174622_add_spec_json_to_templates": "ecd7869cd86c451b0ff134aff944b6e2c22f9b31", - "20170915205722_create_dns_encoded_networks_and_instance_groups": "8e0832e495000c488d0a100a8b3162e7d82dcaea", - "20171010144941_add_configs": "04348263d89a61dd1078c9ee4a2c94da5a1ff012", - "20171010150659_migrate_runtime_configs": "4b6ee608a317656dd3f4260dd2c554068dbe6968", - "20171010161532_migrate_cloud_configs": "88816313055e4dfeb1816d73831a2e7a1c4b259c", - "20171011122118_migrate_cpi_configs": "78b31890a8f2ce9bd1bb8b5d9a26bed69fb6dc30", - "20171018102040_remove_compilation_local_dns_records": "5bb71074f5dfab23c1caef1a9fb1779190cb76d3", - "20171030224934_convert_nil_configs_to_empty": "38992699f41df50e7b4b869a9e89a2fd2d8770f2", - "20171104185823_add_manifest_text_to_deployments": "fbb7a4d05c9e12ad6d1fdf3ec04fc5dccf09cad1", - "20171113000000_add_links_api": "3e852a8b0d8b8ce46a4e8a3c59dc7f6125606c5f", - "20171117230219_add_network_spec_to_vms": "86943d47455e06382190cef6ee6faea71dd1151f", - "20171201153629_remove_unused_template_columns": "a1853f2f9c44a82717dba7809ae5149789b95d01", - "20180119183014_add_stemcell_matches": "c01cc3aefbfd865086c839ca794f1235f16932a0", - "20180119233828_add_vm_id_to_ip_addresses": "128151233382b1482dab8029ee61bf0774c27ed7", - "20180130182844_rename_stemcell_matches_to_stemcell_uploads": "e6b72ee8aab1f46893ca25245745371defa5cbf7", - "20180130182845_add_team_id_to_configs": "aea2f011f14db397c57df44712106f1161cb1edd", - "20180215152554_add_api_version_to_stemcells": "94400dcd0ec9f2eb3607e7f7483b207d4da7ce5a", - "20180301204622_add_stemcell_api_version_to_vms": "d51e2a411900f20847ff439225c27da6b9e60f8f", - "20180405233153_remove_instance_from_orphaned_vms": "e06508c28f2619548f6dcfe5e5c46787d17c18b6", - "20180410180821_migrate_legacy_update_strategy": "9f224e6079b779638a3a52e01dc9fefbc3a2bfd8", - "20180411165035_migrate_update_strategy_to_vm_strategy": "116a03febc41f331316bb0d14385093ed941bc68", - "20180427184448_add_historical_metadata_to_orphaned_vms": "405597203ab69f062481a9896a667617bc3207f7", - "20180515204145_add_vm_metadata_spec": "3a094f32feef551247aeb82432cb551d4804ac16", - "20180613190204_links_api_longtext_support": "555ab4f70cc81a7a5889429f8ddadb08dcd432f0", - "20180822230006_create_network_table": "167d33bbd968ad671f2c1f7bac5d5046e77edd4f", - "20181017210108_add_type_to_local_dns_encoded_instance_group": "c381ec9869bd19121f80f7a9c99213dbce55c680", - "20181017233927_add_links_json_to_local_dns_record": "90ad875b1b9ab1aa665951c10a7c1b09076779e6", - "20181019225226_rename_table_local_dns_encoded_instance_group": "b8a98f3b040a03f8ee30a39d5c9d3bd5102858fe", - "20190104135624_add_update_completed_to_release_versions": "648645410ac265aa009e70d3a5cc6f403febde5f", - "20190114153103_add_index_to_tasks": "50f68f6f1b0ce5765af6417a8b9bc0e1ffd5bb04", - "20190313231924_remove_constraints_from_local_dns_blobs": "944bca2751c4c12680cbda63dfd35e7b15dac932", - "20190314182109_add_records_version_to_local_dns_blobs": "b7f87c3fffe68a8e9d283e123693f4c30faf4c74", - "20190314192454_create_local_dns_aliases": "6f83477c4ed3877ecd4687a4d709791053e27d45", - "20190315163632_add_aliases_version_to_local_dns_blobs": "1bb8d26c85c5a7fa4ab032b08407fc03f7b5c8c3", - "20190318234554_add_criteria_columns_to_local_dns_aliases": "8f36cbe5cf9759ad6b903e8c08dc0cf388260cef", - "20190325095716_remove_resurrection_paused": "546c855e7d2ee00a4f9867ab1d819847781a06de", - "20190327222054_scale_dns_blob_version": "2460bacc06eae7368d9322a97bfe781a10c59d3f", - "20210902232124_add_blobstore_and_nats_shas_to_vms": "7710e2c2c9589865382daaa456bd0e95b22ba3b6", - "20230103143246_add_permanent_nats_credentials_to_vms": "a01b24aa3891d6bb0eb4e4032553d4e9871a19e0", - "20240319204601_remove_dns_records_from_instances": "bb637d410772d09caabdb68a1126fbc9f9b4deec" -} \ No newline at end of file diff --git a/src/bosh-director/lib/bosh/director/tasks/db.rake b/src/bosh-director/lib/bosh/director/tasks/db.rake index d250d9e8072..6f99afe9757 100644 --- a/src/bosh-director/lib/bosh/director/tasks/db.rake +++ b/src/bosh-director/lib/bosh/director/tasks/db.rake @@ -5,8 +5,8 @@ namespace :db do name = args.to_hash.fetch(:name) timestamp = Time.new.getutc.strftime('%Y%m%d%H%M%S') - new_migration_path = "bosh-director/db/migrations/director/#{timestamp}_#{name}.rb" - new_migration_spec_path = "bosh-director/spec/unit/db/migrations/director/#{timestamp}_#{name}_spec.rb" + new_migration_path = "bosh-director/db/migrations/#{timestamp}_#{name}.rb" + new_migration_spec_path = "bosh-director/spec/unit/db/migrations/#{timestamp}_#{name}_spec.rb" puts "Creating #{new_migration_spec_path}" File.write new_migration_spec_path, < [:blob_id], :unique => false] + else + [] + end + end + + it 'has expected indexes on local_dns_blobs.blob_id' do + expect(local_dns_blobs_indexes.values).to eq(expected_indexes) + end + end + end + + describe '20170203212124_add_variables' do + let(:deployment_data_0) do + { id: 1, name: 'FAKE_DEPLOYMENT_NAME_0' } + end + let(:deployment_data_1) do + { id: 2, name: 'FAKE_DEPLOYMENT_NAME_1' } + end + + before do + db[:deployments] << deployment_data_0 + db[:deployments] << deployment_data_1 + end + + describe 'variable_sets table' do + it 'has a non null constraint for deployment_id' do + expect { + db[:variable_sets] << { id: 100, deployment_id: nil, created_at: Time.now } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a non null constraint for created_at' do + expect { + db[:variable_sets] << { id: 100, deployment_id: deployment_data_0[:id], created_at: nil } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'defaults deploy_success to false' do + db[:variable_sets] << { id: 100, deployment_id: deployment_data_0[:id], created_at: Time.now } + expect(db[:variable_sets].first['deploy_success']).to be_falsey + end + + it 'has a foreign key association with deployments table' do + expect { + db[:variable_sets] << { id: 100, deployment_id: 646464, created_at: Time.now } + }.to raise_error Sequel::ForeignKeyConstraintViolation + end + + it 'cascades on deployment deletion' do + db[:variable_sets] << { id: 100, deployment_id: deployment_data_0[:id], created_at: Time.now } + db[:variable_sets] << { id: 200, deployment_id: deployment_data_0[:id], created_at: Time.now } + db[:variable_sets] << { id: 300, deployment_id: deployment_data_1[:id], created_at: Time.now } + + expect(db[:variable_sets].count).to eq(3) + + db[:deployments].where(id: 1).delete + + expect(db[:variable_sets].count).to eq(1) + expect(db[:variable_sets].where(deployment_id: deployment_data_0[:id]).count).to eq(0) + end + end + + describe 'variables table' do + before do + db[:variable_sets] << { id: 100, deployment_id: deployment_data_0[:id], created_at: Time.now } + db[:variable_sets] << { id: 200, deployment_id: deployment_data_0[:id], created_at: Time.now } + db[:variable_sets] << { id: 300, deployment_id: deployment_data_1[:id], created_at: Time.now } + end + + it 'has a non null constraint for variables.variable_id' do + expect { + db[:variables] << { variable_name: 'var_1', variable_id: nil, variable_set_id: 100 } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a non null constraint for variables.variable_name' do + expect { + db[:variables] << { variable_name: nil, variable_id: 'var_id_1', variable_set_id: 100 } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a non null constraint for variables.variable_set_id' do + expect { + db[:variables] << { variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: nil } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a foreign key constraint on variables.variable_set_id with variable_sets.id' do + expect { + db[:variables] << { id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 9999 } + }.to raise_error(Sequel::ForeignKeyConstraintViolation) + end + + it 'cascades on variable_sets deletion' do + db[:variables] << { id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100 } + db[:variables] << { id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 100 } + db[:variables] << { id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200 } + + expect(db[:variables].count).to eq(3) + + db[:variable_sets].where(id: 100).delete + + expected_variable_data = + { + id: 3, + is_local: true, + provider_deployment: '', + variable_id: 'var_id_3', + variable_name: 'var_3', + variable_set_id: 200, + } + + expect(db[:variables].count).to eq(1) + expect(db[:variables].first).to eq(expected_variable_data) + end + + it 'cascades on deployment deletion' do + db[:variables] << { id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100 } + db[:variables] << { id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 100 } + db[:variables] << { id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 300 } + + expect(db[:variables].count).to eq(3) + + db[:deployments].where(id: 1).delete + + expect(db[:variables].count).to eq(1) + expect(db[:variables].where(variable_set_id: 300).count).to eq(1) + end + + it 'has variable_set_id and variable_name unique constraint' do + db[:variables] << { id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100 } + + expect { + db[:variables] << { id: 2, variable_id: 'var_id_2', variable_name: 'var_1', variable_set_id: 100 } + }.to raise_error(Sequel::UniqueConstraintViolation) + end + end + + describe 'instances table' do + let(:instance_data) do + { + job: 'job', + index: 1, + deployment_id: deployment_data_0[:id], + state: 'running', + variable_set_id: db[:variable_sets].first[:id], + } + end + + before do + db[:variable_sets] << { id: 100, deployment_id: deployment_data_0[:id], created_at: Time.now } + end + + it 'does not allow null for variable_set_id column' do + instance_data[:variable_set_id] = nil + + expect { db[:instances] << instance_data }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a foreign key constraint between instances.variable_set_id and variable_sets.id' do + instance_data[:variable_set_id] = 99999 + + expect { db[:instances] << instance_data }.to raise_error(Sequel::ForeignKeyConstraintViolation) + end + end + end + + describe '20170217000000_variables_instance_table_foreign_key_update' do + let(:variable_set_id_constraint) do + db.foreign_key_list(:instances).select { |v| v[:columns] == [:variable_set_id] } + end + + it 'instances table has foreign key constraint on [variable_set_id]' do + expected_constraint = + case db.adapter_scheme + when :sqlite + { + columns: [:variable_set_id], + table: :variable_sets, + } + else + { + columns: [:variable_set_id], + table: :variable_sets, + key: [:id], + } + end + + expect(variable_set_id_constraint.size).to eq(1) + expect(variable_set_id_constraint.first).to include(expected_constraint) + end + end + + describe '20170303175054_expand_template_json_column_lengths' do + let(:large_json) { JSON.dump({ key: ('foo' * 1000) }) } + + before do + db[:releases] << { name: 'FAKE_RELEASE_NAME' } + end + + it 'allows large amounts of text in provides_json consumes_json columns' do + expect { + db[:templates] << { + id: 1, + name: 'FAKE_TEMPLATE_NAME', + release_id: db[:releases].first[:id], + version: 'FAKE_VERSION', + blobstore_id: 'FAKE_BLOBSTORE_ID', + sha1: "FAKE_SHA1", + package_names_json: large_json, + spec_json: large_json, + } + }.not_to raise_error + + expect(db[:templates].first[:spec_json]).to eq(large_json) + expect(db[:templates].first[:package_names_json]).to eq(large_json) + end + end + + describe '20170328224049_associate_vm_info_with_vms_table' do + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME', } + db[:variable_sets] << { deployment_id: db[:deployments].first[:id], created_at: Time.now } + db[:instances] << { + job: 'blah', + index: 0, + deployment_id: db[:deployments].first[:id], + variable_set_id: db[:variable_sets].first[:id], + state: 'running', + } + end + + it 'has a uniqueness constraint on vms.agent_id' do + db[:vms] << { agent_id: 1, instance_id: db[:instances].first[:id] } + + expect { + db[:vms] << { agent_id: 1, instance_id: db[:instances].first[:id] } + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a uniqueness constraint on vms.cid' do + db[:vms] << { cid: 1, instance_id: db[:instances].first[:id] } + + expect { + db[:vms] << { cid: 1, instance_id: db[:instances].first[:id] } + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a foreign key constraint between vms.instance_id and instances.id' do + expect { db[:vms] << { instance_id: 999 } }.to raise_error(Sequel::ForeignKeyConstraintViolation) + end + + it 'has a not null constraint on vms.instances_id' do + expect { db[:vms] << { instance_id: nil } }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20170405144414_add_cross_deployment_links_support_for_variables' do + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME', } + db[:variable_sets] << { deployment_id: db[:deployments].first[:id], created_at: Time.now } + end + + it 'adds a new unique index for :variable_set_id, :variable_name, and :provider_deployment' do + variable_data = + { + variable_id: 'var_id_3', + variable_name: 'var_3', + variable_set_id: db[:variable_sets].first[:id], + provider_deployment: 'test', + } + + db[:variables] << variable_data + + expect { + db[:variables] << variable_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + end + + describe '20170405181126_backfill_local_dns_records_and_drop_name' do + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME', } + db[:variable_sets] << { deployment_id: db[:deployments].first[:id], created_at: Time.now } + db[:instances] << { + job: 'blah', + index: 0, + deployment_id: db[:deployments].first[:id], + variable_set_id: db[:variable_sets].first[:id], + state: 'running', + } + instance = db[:instances].first + deployment = db[:deployments].first(id: instance[:deployment_id]) + + db[:local_dns_records] << { + instance_id: instance[:id], + instance_group: instance[:job], + az: instance[:availability_zone], + network: 'FAKE_NETWORK_NAME', + deployment: deployment[:name], + ip: 'FAKE_IP', + } + end + + it 'does not cascade deletion of local_dns_records when deleting instances' do + expect { + db[:instances].delete + }.to raise_error(Sequel::ForeignKeyConstraintViolation) + end + end + + describe '20170427194511_add_runtime_config_name_support' do + it 'has a null constraint on runtime_configs.name' do + expect { + db[:runtime_configs] << { properties: 'FAKE_PROPERTIES', name: nil, created_at: Time.now } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20170503205545_change_id_local_dns_to_bigint' do + let(:large_integer_id) { 9223372036854775807 } + let(:local_dns_blob_data) do + { + created_at: Time.now, + version: 2, + } + end + let(:agent_dns_version_data) do + { + agent_id: 'FAKE_AGENT_ID', + dns_version: 2, + } + end + + it 'has allows large integers for local_dns_records.id' do + db[:local_dns_records] << { id: large_integer_id, ip: 'FAKE_IP' } + + expect(db[:local_dns_records].where(id: large_integer_id).count).to eq(1) + end + + it 'has allows large integers for local_dns_records.id' do + local_dns_blob_data[:id] = large_integer_id + db[:local_dns_blobs] << local_dns_blob_data + + expect(db[:local_dns_blobs].where(id: large_integer_id).count).to eq(1) + end + + it 'has allows large integers for local_dns_records.version' do + local_dns_blob_data[:version] = large_integer_id + db[:local_dns_blobs] << local_dns_blob_data + + expect(db[:local_dns_blobs].where(version: large_integer_id).count).to eq(1) + end + + it 'has allows large integers for agent_dns_versions.id' do + agent_dns_version_data[:id] = large_integer_id + db[:agent_dns_versions] << agent_dns_version_data + + expect(db[:agent_dns_versions].where(id: large_integer_id).count).to eq(1) + end + + it 'has allows large integers for agent_dns_versions.dns_version' do + agent_dns_version_data[:dns_version] = large_integer_id + db[:agent_dns_versions] << agent_dns_version_data + + expect(db[:agent_dns_versions].where(dns_version: large_integer_id).count).to eq(1) + end + end + + describe '20170607182149_add_task_id_to_locks' do + it 'has a null constraint on locks.task_id' do + expect { + db[:locks] << { name: 'FAKE_LOCK_NAME', uid: 'FAKE_UUID', task_id: nil, expired_at: Time.now } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20170628221611_add_canonical_az_names_and_ids' do + it 'has a uniqueness constraint on local_dns_encoded_azs.name' do + local_dns_encoded_az_data = { name: 'FAKE_LOCAL_DNS_ENCODED_AZ_NAME' } + db[:local_dns_encoded_azs] << local_dns_encoded_az_data + + expect { + db[:local_dns_encoded_azs] << local_dns_encoded_az_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a null constraint on local_dns_encoded_azs.name' do + expect { + db[:local_dns_encoded_azs] << { name: nil } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20170815175515_change_variable_ids_to_bigint' do + let(:large_integer_id) { 9223372036854775807 } + + before do + db[:deployments] << { name: 'FAKE_RELEASE_NAME' } + end + + it 'has allows large integers for variable_sets.id' do + db[:variable_sets] << { + id: large_integer_id, + deployment_id: db[:deployments].first[:id], + created_at: Time.now, + } + + expect(db[:variable_sets].where(id: large_integer_id).count).to eq(1) + end + + it 'has allows large integers for variables.id' do + db[:variable_sets] << { deployment_id: db[:deployments].first[:id], created_at: Time.now } + db[:variables] << { + id: large_integer_id, + variable_set_id: db[:variable_sets].first[:id], + variable_id: 'FAKE_VARIABLE_ID', + variable_name: 'FAKE_VARIABLE_NAME', + } + + expect(db[:variables].where(id: large_integer_id).count).to eq(1) + end + end + + describe '20170825141953_change_address_to_be_string_for_ipv6' do + it 'has a uniqueness constraint on ip_addresses.address_str' do + ip_address_data = { address_str: 'FAKE_ADDRESS_STR' } + + db[:ip_addresses] << ip_address_data + expect { + db[:ip_addresses] << ip_address_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a null constraint on ip_addresses.address_str' do + expect { + db[:ip_addresses] << { address_str: nil } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20170915205722_create_dns_encoded_networks_and_instance_groups' do + let(:local_dns_encoded_group_data) do + { name: 'FAKE_NAME', deployment_id: db[:deployments].first[:id] } + end + + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME' } + end + + it 'has a uniqueness constraint on local_dns_encoded_groups.name' do + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + expect { + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a null constraint on local_dns_encoded_groups.name' do + local_dns_encoded_group_data[:name] = nil + + expect { + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a null constraint on local_dns_encoded_groups.deployment_id' do + local_dns_encoded_group_data[:deployment_id] = nil + + expect { + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + }.to raise_error(Sequel::NotNullConstraintViolation) + end + + it 'has a uniqueness constraint on local_dns_encoded_networks.name' do + local_dns_encoded_network_data = { name: 'FAKE_NAME' } + + db[:local_dns_encoded_networks] << local_dns_encoded_network_data + expect { + db[:local_dns_encoded_networks] << local_dns_encoded_network_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a null constraint on local_dns_encoded_networks.name' do + expect { + db[:local_dns_encoded_networks] << { name: nil } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20171030224934_convert_nil_configs_to_empty' do + it 'has a null constraint on configs.content' do + expect { + db[:configs] << { + type: 'FAKE_TYPE', + name: 'FAKE_NAME', + created_at: Time.now, + content: nil, + } + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20171113000000_add_links_api' do + let(:instance_data) do + { + job: 'job', + index: 1, + deployment_id: db[:deployments].first[:id], + state: 'running', + variable_set_id: db[:variable_sets].first[:id], + } + end + let(:link_consumer_data) do + { + deployment_id: db[:deployments].first[:id], + instance_group: 'FAKE_INSTANCE_GROUP', + name: 'FAKE_JOB', + type: 'FAKE_TYPE', + } + end + let(:link_provider_data) do + { + deployment_id: db[:deployments].first[:id], + instance_group: 'FAKE_INSTANCE_GROUP', + name: 'FAKE_JOB', + type: 'FAKE_TYPE', + } + end + let(:link_provider_intent_data) do + { + link_provider_id: db[:link_providers].first[:id], + original_name: 'FAKE_ORIGINAL_NAME', + type: 'FAKE_TYPE', + } + end + let(:link_consumer_intent_data) do + { + link_consumer_id: db[:link_consumers].first[:id], + original_name: 'FAKE_ORIGINAL_NAME', + type: 'FAKE_TYPE', + } + end + + before do + db[:deployments] << { name: 'FAKE_RELEASE_NAME' } + db[:variable_sets] << { deployment_id: db[:deployments].first[:id], created_at: Time.now } + + db[:link_consumers] << link_consumer_data + db[:link_providers] << link_provider_data + + db[:link_provider_intents] << link_provider_intent_data + db[:link_consumer_intents] << link_consumer_intent_data + end + + it 'has a uniqueness constraint on link_providers [deployment_id, instance_group, name, type]' do + expect { + db[:link_providers] << link_provider_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a uniqueness constraint on link_consumers [deployment_id, instance_group, name, type]' do + expect { + db[:link_consumers] << link_consumer_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a uniqueness constraint on link_provider_intents [link_provider_id, original_name, type]' do + expect { + db[:link_provider_intents] << link_provider_intent_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a uniqueness constraint on link_consumer_intents [link_consumer_id, original_name, type]' do + expect { + db[:link_consumer_intents] << link_consumer_intent_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + + it 'has a uniqueness constraint on instances_links [link_id, instance_id]' do + db[:instances] << instance_data + db[:links] << { + link_provider_intent_id: db[:link_provider_intents].first[:id], + link_consumer_intent_id: db[:link_consumer_intents].first[:id], + name: 'FAKE_LINK_NAME', + link_content: 'FAKE_LINK_CONTENT' + } + + instances_link_data = { + instance_id: db[:instances].first[:id], + link_id: db[:links].first[:id], + } + + db[:instances_links] << instances_link_data + expect { + db[:instances_links] << instances_link_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + end + + describe '20180119183014_add_stemcell_matches / 20180130182844_rename_stemcell_matches_to_stemcell_uploads' do + let(:stemcell_uploads_data) do + { + name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', + version: '3468.19', + cpi: 'aws-use1', + } + end + + it 'has a uniqueness constraint on stemcell_uploads [name, version, cpi]' do + db[:stemcell_uploads] << stemcell_uploads_data + + expect { + db[:stemcell_uploads] << stemcell_uploads_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + end + + describe '20180613190204_links_api_longtext_support' do + let(:large_json) { JSON.dump({ key: ('foo' * 1000) }) } + + let(:link_provider_data) do + { + deployment_id: db[:deployments].first[:id], + instance_group: 'FAKE_INSTANCE_GROUP', + name: 'FAKE_JOB', + type: 'FAKE_TYPE', + } + end + let(:link_provider_intent_data) do + { + link_provider_id: db[:link_providers].first[:id], + original_name: 'FAKE_ORIGINAL_NAME', + type: 'FAKE_TYPE', + metadata: large_json, + } + end + + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME' } + db[:link_providers] << link_provider_data + end + + it 'allows large amounts of text in provides_json consumes_json columns' do + db[:link_provider_intents] << link_provider_intent_data + expect(db[:link_provider_intents].first[:metadata]).to eq(large_json) + end + end + + describe '20181017210108_add_type_to_local_dns_encoded_instance_group' do + let(:local_dns_encoded_group_data) do + { + type: 'FAKE_TYPE', + name: 'FAKE_NAME', + deployment_id: db[:deployments].first[:id], + } + end + + before do + db[:deployments] << { name: 'FAKE_DEPLOYMENT_NAME' } + end + + it 'has a uniqueness constraint on local_dns_encoded_instance_group [name, type, deployment_id]' do + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + + expect { + db[:local_dns_encoded_groups] << local_dns_encoded_group_data + }.to raise_error(Sequel::UniqueConstraintViolation) + end + end + + describe '20190104135624_add_update_completed_to_release_versions' do + let(:release_version_data) do + { + release_id: db[:releases].first[:id], + version: 'FAKE_VERSION', + commit_hash: 'UUID_FAKE_COMMIT_HASH', + update_completed: nil, + } + end + + before do + db[:releases] << { name: 'FAKE_RELEASE_NAME' } + end + + it 'has a null constraint on release_versions.update_completed' do + expect { + db[:release_versions] << release_version_data + }.to raise_error(Sequel::NotNullConstraintViolation) + end + end + + describe '20190114153103_add_index_to_tasks' do + it 'have an index on tasks.type' do + indexes_on_tasks = db.indexes(:tasks) + + expect(indexes_on_tasks.values.select { |i| i[:columns] == [:type] }).not_to be_empty + end + end + end +end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb similarity index 97% rename from src/bosh-director/spec/unit/db/migrations/director/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb rename to src/bosh-director/spec/unit/db/migrations/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb index 519113fca9d..a4d28de8b87 100644 --- a/src/bosh-director/spec/unit/db/migrations/director/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb +++ b/src/bosh-director/spec/unit/db/migrations/20210902232124_add_blobstore_and_nats_shas_to_vms_spec.rb @@ -1,4 +1,4 @@ -require_relative '../../../../db_spec_helper' +require 'db_spec_helper' module Bosh::Director describe '20210902232124_add_blobstore_and_nats_shas_to_vms.rb' do diff --git a/src/bosh-director/spec/unit/db/migrations/director/20230103143246_add_permanent_nats_credentials_to_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/20230103143246_add_permanent_nats_credentials_to_vms_spec.rb similarity index 100% rename from src/bosh-director/spec/unit/db/migrations/director/20230103143246_add_permanent_nats_credentials_to_vms_spec.rb rename to src/bosh-director/spec/unit/db/migrations/20230103143246_add_permanent_nats_credentials_to_vms_spec.rb diff --git a/src/bosh-director/spec/unit/db/migrations/director/20240319204601_remove_dns_records_from_instances_spec.rb b/src/bosh-director/spec/unit/db/migrations/20240319204601_remove_dns_records_from_instances_spec.rb similarity index 100% rename from src/bosh-director/spec/unit/db/migrations/director/20240319204601_remove_dns_records_from_instances_spec.rb rename to src/bosh-director/spec/unit/db/migrations/20240319204601_remove_dns_records_from_instances_spec.rb diff --git a/src/bosh-director/spec/unit/db/migrations/director/20151229184742_add_vm_attributes_to_instance_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20151229184742_add_vm_attributes_to_instance_spec.rb deleted file mode 100644 index f35643a4246..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20151229184742_add_vm_attributes_to_instance_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_vm_attributes_to_instance' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20151229184742_add_vm_attributes_to_instance.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'runs drop_vm_env_json_from_instance migration and retains data' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}'} - db[:vms] << { - id: 1, - agent_id: 'fake-agent-id', - cid: 'fake-vm-cid', - env_json: 'fake-env-json', - trusted_certs_sha1: 'fake-trusted-certs-sha1', - credentials_json: 'fake-credentials-json', - deployment_id: 1 - } - db[:instances] << {id: 1, job: 'fake-job', index: 1, deployment_id: 1, vm_id: 1, state: 'started'} - - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(1) - expect(db[:instances].first[:vm_cid]).to eq('fake-vm-cid') - expect(db[:instances].first[:agent_id]).to eq('fake-agent-id') - expect(db[:instances].first[:vm_env_json]).to eq('fake-env-json') - expect(db[:instances].first[:trusted_certs_sha1]).to eq('fake-trusted-certs-sha1') - expect(db[:instances].first[:credentials_json]).to eq('fake-credentials-json') - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version_spec.rb deleted file mode 100644 index c99ca878a4e..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_vm_attributes_to_instance' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:stemcells] << { - id: 1, - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - operating_system: stemcell_os, - version: '9999.1', - cid: 'ami-12341234' - } - db[:releases] << { - id: 1, - name: 'test_release', - } - db[:packages] << { - id: 1, - release_id: 1, - name: 'test_package', - version: 'abcd1234', - dependency_set_json: '{}', - } - db[:compiled_packages] << { - id: 1, - build: 1, - package_id: 1, - stemcell_id: 1, - sha1: 'abcd1234', - blobstore_id: '1234abcd', - dependency_key: '{}', - dependency_key_sha1: 'abcd1234', - } - end - let(:stemcell_os) { 'ubuntu_trusty' } - - it 'runs drop_vm_env_json_from_instance migration and retains data' do - DBSpecHelper.migrate(migration_file) - - expect(db[:compiled_packages].count).to eq(1) - expect(db[:compiled_packages].first).to_not have_key(:stemcell_id) - expect(db[:compiled_packages].first[:stemcell_os]).to eq('ubuntu_trusty') - expect(db[:compiled_packages].first[:stemcell_version]).to eq('9999.1') - end - - context 'when stemcell does not have os version' do - let(:stemcell_os) { nil } - - it 'sets stemcell_os as stemcell name' do - DBSpecHelper.migrate(migration_file) - - expect(db[:compiled_packages].count).to eq(1) - expect(db[:compiled_packages].first).to_not have_key(:stemcell_id) - expect(db[:compiled_packages].first[:stemcell_os]).to eq('bosh-aws-xen-hvm-ubuntu-trusty-go_agent') - expect(db[:compiled_packages].first[:stemcell_version]).to eq('9999.1') - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false_spec.rb deleted file mode 100644 index 1a34c897efe..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160329201256_set_instances_with_nil_serial_to_false_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'set_instances_with_nil_serial_to_false' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160329201256_set_instances_with_nil_serial_to_false.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'updates instances\'s update properties "serial" from nil to false' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}'} - db[:instances] << {id: 1, job: 'fake-job', index: 1, deployment_id: 1, state: 'started'} - db[:instances] << { - id: 2, - job: 'fake-job', - index: 2, - deployment_id: 1, - state: 'started', - spec_json: '{"update":{"serial":null}}' - } - db[:instances] << { - id: 3, - job: 'fake-job', - index: 3, - deployment_id: 1, - state: 'started', - spec_json: '{"update":{"serial":true}}' - } - db[:instances] << { - id: 4, - job: 'fake-job', - index: 4, - deployment_id: 1, - state: 'started', - spec_json: '{"update":{"serial":false}}' - } - db[:instances] << { - id: 5, - job: 'fake-job', - index: 5, - deployment_id: 1, - state: 'started', - spec_json: '{"update":{}}' - } - db[:instances] << { - id: 6, - job: 'fake-job', - index: 6, - deployment_id: 1, - state: 'started', - spec_json: '{}' - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(6) - instances = db[:instances].all.sort_by{|v| v[:id]} - expect(instances[0][:spec_json]).to be_nil - expect(instances[1][:spec_json]).to eq('{"update":{"serial":false}}') - expect(instances[2][:spec_json]).to eq('{"update":{"serial":true}}') - expect(instances[3][:spec_json]).to eq('{"update":{"serial":false}}') - expect(instances[4][:spec_json]).to eq('{"update":{}}') - expect(instances[5][:spec_json]).to eq('{}') - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160331225404_backfill_stemcell_os_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160331225404_backfill_stemcell_os_spec.rb deleted file mode 100644 index 9d221b6e833..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160331225404_backfill_stemcell_os_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'backfill_stemcell_os' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160331225404_backfill_stemcell_os.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'populates stemcell\'s operating system column, if empty' do - db[:stemcells] << {id: 1, name: 'fake-stem-1', version: 'fake-version-1', cid: 'fake-cid-1'} - db[:stemcells] << {id: 2, name: 'fake-stem-2', version: 'fake-version-2', cid: 'fake-cid-2', operating_system: 'fake-operating-system'} - db[:stemcells] << {id: 3, name: 'fake-stem-3', version: 'fake-version-3', cid: 'fake-cid-3', operating_system: ''} - db[:stemcells] << {id: 4, name: 'fake-stem-4', version: 'fake-version-4', cid: 'fake-cid-4', operating_system: nil} - - DBSpecHelper.migrate(migration_file) - - stemcells = db[:stemcells].all.sort_by{|e| e[:id]} - expect(stemcells[0][:operating_system]).to eq(stemcells[0][:name]) - expect(stemcells[1][:operating_system]).to eq('fake-operating-system') - expect(stemcells[2][:operating_system]).to eq(stemcells[2][:name]) - expect(stemcells[3][:operating_system]).to eq(stemcells[3][:name]) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160414183654_set_teams_on_task_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160414183654_set_teams_on_task_spec.rb deleted file mode 100644 index ba37b6b3b4c..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160414183654_set_teams_on_task_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'set_teams_on_task' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160414183654_set_teams_on_task.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'allows teams to optionally be added to tasks' do - db[:tasks] << { - id: 1, - state: 'finished', - type: 'something', - deployment_name: 'test-deployment', - timestamp: '2016-04-14 11:53:42', - description: 'delete_deployment', - } - - DBSpecHelper.migrate(migration_file) - - db[:tasks] << { - id: 2, - state: 'finished', - type: 'something', - deployment_name: 'other-deployment', - timestamp: '2016-04-14 11:53:42', - description: 'delete_deployment', - teams: 'dev,qa', - } - - db[:tasks] << { - id: 3, - state: 'finished', - type: 'something', - deployment_name: 'other-deployment', - timestamp: '2016-04-14 11:53:42', - description: 'delete_deployment', - } - - tasks = db[:tasks].all - expect(tasks.count).to eq(3) - expect(tasks[0][:teams]).to be_nil - expect(tasks[1][:teams]).to eq('dev,qa') - expect(tasks[2][:teams]).to be_nil - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160427164345_add_teams_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160427164345_add_teams_spec.rb deleted file mode 100644 index a3a3c65abb8..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160427164345_add_teams_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_teams' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160427164345_add_teams.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'migrates deployment teams over to Teams table' do - db[:deployments] << {id: 1, name: 'deployment_with_teams', teams: 'prod,the-best'} - db[:deployments] << {id: 2, name: 'other_deployment_with_teams', teams: 'prod,aspiring'} - - DBSpecHelper.migrate(migration_file) - - teams = db[:teams].all - expect(teams.count).to eq(3) - expect(teams.map{|i| i[:name]}.sort).to eq(['aspiring','prod','the-best']) - end - - it 'preserves the teams associated with a deployment using a many-to-many table' do - db[:deployments] << {id: 1, name: 'deployment_with_teams', teams: 'prod,the-best'} - db[:deployments] << {id: 2, name: 'other_deployment_with_teams', teams: 'prod,aspiring'} - - DBSpecHelper.migrate(migration_file) - - deployments_teams = db[:deployments_teams].all - expect(deployments_teams.count).to eq(4) - expect(deployments_teams.select{|i| i[:deployment_id] == 1}.map{|i| i[:team_id]}.sort).to eq([1,2]) - expect(deployments_teams.select{|i| i[:deployment_id] == 2}.map{|i| i[:team_id]}.sort).to eq([1,3]) - end - - it 'should check that deployments_teams has unique deployment_id and team_id pairs' do - db[:deployments] << {id: 1, name: 'deployment_with_teams', teams: 'prod,the-best'} - - DBSpecHelper.migrate(migration_file) - - expect { - db[:deployments_teams] << {deployment_id: 1, team_id: 2} - }.to raise_error Sequel::UniqueConstraintViolation - end - - it 'removes the teams column from deployment' do - db[:deployments] << {id: 1, name: 'deployment_with_teams', teams: 'prod,the-best'} - db[:deployments] << {id: 2, name: 'other_deployment_with_teams', teams: 'prod,aspiring'} - db[:deployments] << {id: 3, name: 'deployment_without_teams'} - - DBSpecHelper.migrate(migration_file) - - deployments = db[:deployments].all - deployment_fields = deployments.map(&:keys).uniq.flatten - expect(deployments.count).to eq(3) - expect(deployment_fields).to eq([:id, :name, :manifest, :cloud_config_id, :link_spec_json, :runtime_config_id]) - end - - it 'removes the teams column from tasks' do - db[:tasks] << {id: 1, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type', teams: 'prod,the-best' } - db[:tasks] << {id: 2, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type',teams: 'prod,aspiring' } - db[:tasks] << {id: 3, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type',} - - DBSpecHelper.migrate(migration_file) - - tasks = db[:tasks].all - tasks_fields = tasks.map(&:keys).uniq.flatten - expect(tasks.count).to eq(3) - expect(tasks_fields).to eq([:id, :state, :timestamp, :description, :result, :output, :checkpoint_time, :type, :username, :deployment_name, :started_at]) - end - - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql_spec.rb deleted file mode 100644 index 69bc90b6cb6..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160614182106_change_text_to_longtext_for_mysql_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'changed_text_to_longtext_for_mysql' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160614182106_change_text_to_longtext_for_mysql.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'ensures that fields allow texts longer than 65535 character' do - DBSpecHelper.migrate(migration_file) - - really_long_links_spec = 'a' * 65536 - db[:deployments] << {name: 'deployment', link_spec_json: really_long_links_spec} - - expect(db[:deployments].map{|cp| cp[:link_spec_json].length}).to eq([really_long_links_spec.length]) - end - - it 'migrates data over without data loss' do - db[:stemcells] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - operating_system: 'stemcell_os', - version: '9999.1', - cid: 'ami-12341234' - } - db[:releases] << { - name: 'test_release', - } - db[:packages] << { - release_id: 1, - name: 'test_package', - version: 'abcd1234', - dependency_set_json: 'dependency_set_json', - } - db[:compiled_packages] << { - build: 1, - package_id: 1, - sha1: 'abcd1234', - blobstore_id: '1234abcd', - dependency_key: 'dependency_key', - dependency_key_sha1: 'abcd1234', - } - db[:deployments] << { - name: 'deployment_with_teams', - link_spec_json: 'link_spec_json' - } - db[:deployment_problems] << { - deployment_id: 1, - state: 'running', - resource_id: 1, - type: 'type', - data_json: 'data_json', - created_at: Time.now, - last_seen_at: Time.now, - } - db[:deployment_properties] << { - deployment_id: 1, - name: 'property', - value: 'value' - } - db[:director_attributes] << { - name: 'director_attributes_name', - value: 'director_attributes_value' - } - db[:events] << { - user: 'user1', - timestamp: Time.now, - action: 'action', - object_type: 'object_type', - error: 'oh noes!', - context_json: '{"error"=>"boo"}' - } - db[:instances] << { - job: 'job', - index: 1, - deployment_id: 1, - cloud_properties: 'cloud_properties', - dns_records: 'dns_records', - spec_json: 'spec_json', - credentials_json: 'credentials_json', - state: 'running' - } - db[:orphan_disks] << { - disk_cid: 'disk_cid', - deployment_name: 'deployment_name', - instance_name: 'instance_name', - cloud_properties_json: 'cloud_properties_json', - created_at: Time.now - } - db[:persistent_disks] << { - instance_id: 1, - disk_cid: 1, - cloud_properties_json: 'cloud_properties_json', - } - db[:templates] << { - name: 'name', - version: 'version', - blobstore_id: 'blobstore_id', - sha1: 'sha1', - package_names_json: 'package_names_json', - release_id: 1, - logs_json: 'logs_json', - properties_json: 'properties_json' - } - - - DBSpecHelper.migrate(migration_file) - - expect(db[:compiled_packages].map{|cp| cp[:dependency_key]}).to eq(['dependency_key']) - expect(db[:deployment_problems].map{|cp| cp[:data_json]}).to eq(['data_json']) - expect(db[:deployment_properties].map{|cp| cp[:value]}).to eq(['value']) - expect(db[:deployments].map{|cp| cp[:link_spec_json]}).to eq(['link_spec_json']) - expect(db[:director_attributes].map{|cp| cp[:value]}).to eq(['director_attributes_value']) - expect(db[:events].map{|cp| cp[:error]}).to eq(['oh noes!']) - expect(db[:events].map{|cp| cp[:context_json]}).to eq(['{"error"=>"boo"}']) - expect(db[:instances].map{|cp| cp[:cloud_properties]}).to eq(['cloud_properties']) - expect(db[:instances].map{|cp| cp[:dns_records]}).to eq(['dns_records']) - expect(db[:instances].map{|cp| cp[:spec_json]}).to eq(['spec_json']) - expect(db[:instances].map{|cp| cp[:credentials_json]}).to eq(['credentials_json']) - expect(db[:orphan_disks].map{|cp| cp[:cloud_properties_json]}).to eq(['cloud_properties_json']) - expect(db[:packages].map{|cp| cp[:dependency_set_json]}).to eq(['dependency_set_json']) - expect(db[:persistent_disks].map{|cp| cp[:cloud_properties_json]}).to eq(['cloud_properties_json']) - expect(db[:templates].map{|cp| cp[:package_names_json]}).to eq(['package_names_json']) - expect(db[:templates].map{|cp| cp[:logs_json]}).to eq(['logs_json']) - expect(db[:templates].map{|cp| cp[:properties_json]}).to eq(['properties_json']) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields_spec.rb deleted file mode 100644 index b138943bcec..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160615192201_change_text_to_longtext_for_mysql_for_additional_fields_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'changed_text_to_longtext_for_mysql' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160615192201_change_text_to_longtext_for_mysql_for_additional_fields.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'migrates data over without data loss' do - error = Exception.new('oh noes!') - db[:events] << { - user: 'user1', - timestamp: Time.now, - action: 'action', - object_type: 'object_type', - error: error.to_s, - context_json: '{"error"=>"boo"}' - } - db[:delayed_jobs] << { - priority: 1, - attempts: 2, - handler: 'handler', - last_error: 'last_error' - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:events].map{|cp| cp[:error]}).to eq([error.to_s]) - expect(db[:events].map{|cp| cp[:context_json]}).to eq(['{"error"=>"boo"}']) - expect(db[:delayed_jobs].map{|cp| cp[:handler]}).to eq(['handler']) - expect(db[:delayed_jobs].map{|cp| cp[:last_error]}).to eq(['last_error']) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160803151600_add_name_to_persistent_disks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160803151600_add_name_to_persistent_disks_spec.rb deleted file mode 100644 index 48663fefd2d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160803151600_add_name_to_persistent_disks_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'adding name to persistent disk' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160803151600_add_name_to_persistent_disks.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'sets the default value of the persistent disk name to empty string' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}'} - db[:instances] << {id: 1, job: 'fake-job', index: 1, deployment_id: 1, state: 'started'} - db[:persistent_disks] << { - instance_id: 1, - disk_cid: 'disk-cid', - size: 1024, - active: true, - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:persistent_disks].map{|pd| pd[:name]}).to eq(['']) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20160818112257_change_stemcell_unique_key_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20160818112257_change_stemcell_unique_key_spec.rb deleted file mode 100644 index 33b1b43f275..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20160818112257_change_stemcell_unique_key_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'change stemcell unique key' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20160818112257_change_stemcell_unique_key.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'allows stemcell records with same name, version when cpi differs' do - db[:stemcells] << {name: 'stemcell1', version: 'stemcell-version', cid: 'cid1'} - expect { - db[:stemcells] << {name: 'stemcell1', version: 'stemcell-version', cid: 'cid2'} - }.to raise_error Sequel::UniqueConstraintViolation - - DBSpecHelper.migrate(migration_file) - - # same cpi: fails - db[:stemcells] << {name: 'stemcell3', version: 'stemcell-version', cid: 'cid1', cpi: 'cpi1'} - expect { - db[:stemcells] << {name: 'stemcell3', version: 'stemcell-version', cid: 'cid2', cpi: 'cpi1'} - }.to raise_error Sequel::UniqueConstraintViolation - - # different cpi: works - db[:stemcells] << {name: 'stemcell2', version: 'stemcell-version', cid: 'cid1', cpi: 'cpi1'} - db[:stemcells] << {name: 'stemcell2', version: 'stemcell-version', cid: 'cid2', cpi: 'cpi2'} - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec_spec.rb deleted file mode 100644 index aee5de40659..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20161031204534_populate_lifecycle_on_instance_spec_spec.rb +++ /dev/null @@ -1,114 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'populating lifecycle on instance spec json' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20161031204534_populate_lifecycle_on_instance_spec.rb' } - - let(:manifest_yml) { YAML.dump({'instance_groups' => [{'name' => 'noise'}, instance_group_hash]}) } - let(:spec_json) { JSON.dump({}) } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: manifest_yml} - db[:instances] << {id: 1, job: 'normal_job', index: 1, deployment_id: 1, state: 'started', spec_json: spec_json} - - DBSpecHelper.migrate(migration_file) - end - - context 'when the group does not declare a lifecycle' do - let(:instance_group_hash) do - { 'name' => 'normal_job' } - end - it 'defaults the spec_json lifecycle to service' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq('lifecycle' => 'service') - end - end - - context 'when the group declares a errand lifecycle' do - let(:instance_group_hash) do - { 'name' => 'normal_job', 'lifecycle' => 'errand' } - end - it 'sets the spec_json lifecyle to errand' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq('lifecycle' => 'errand') - end - end - - context 'when the group declares a service lifecycle' do - let(:instance_group_hash) do - { 'name' => 'normal_job', 'lifecycle' => 'service' } - end - it 'sets the spec_json lifecycle to service' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq('lifecycle' => 'service') - end - end - - context 'when the manifest is nil' do - let(:manifest_yml) { nil } - it 'does not update the spec_json' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq({}) - end - end - - context 'when the manifest is empty string' do - let(:manifest_yml) { "" } - it 'does not update the spec_json' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq({}) - end - end - - context 'when the manifest contains a jobs section (and not instance_groups)' do - let(:manifest_yml) { JSON.dump({'jobs' => [{'name' => 'normal_job'}]}) } - it 'sets the spec_json lifecycle to service' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq('lifecycle' => 'service') - end - end - - context 'when the manifest does not contain either jobs or instance_groups' do - let(:manifest_yml) { JSON.dump({}) } - it 'does not update the spec_json' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq({}) - end - end - - context 'when the spec already has unrelated content' do - let(:instance_group_hash) do - { 'name' => 'normal_job' } - end - let(:spec_json) { JSON.dump({'derek' => 'tyler'}) } - it 'does not update the spec_json' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq({'derek' => 'tyler', 'lifecycle' => 'service'}) - end - end - - context 'when the instance has nil spec_json' do - let(:instance_group_hash) do - { 'name' => 'normal_job' } - end - let(:spec_json) { nil } - it 'does not update the spec_json' do - expect(db[:instances].where(id: 1).first[:spec_json]).to eq(nil) - end - end - - context 'when the instance has "" spec_json' do - let(:instance_group_hash) do - { 'name' => 'normal_job' } - end - let(:spec_json) { "" } - it 'does not update the spec_json' do - expect(db[:instances].where(id: 1).first[:spec_json]).to eq("") - end - end - - context 'when the manifest does not contain the instance group name' do - let(:instance_group_hash) do - { 'name' => 'job_that_does_not_exist', 'lifecycle' => 'service' } - end - it 'does not update the spec json' do - expect(JSON.parse(db[:instances].where(id: 1).first[:spec_json])).to eq({}) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20161128181900_add_logs_to_tasks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20161128181900_add_logs_to_tasks_spec.rb deleted file mode 100644 index ca0d3bc2e2e..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20161128181900_add_logs_to_tasks_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'adding event_output and result_output to tasks' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20161128181900_add_logs_to_tasks.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'adds result_output and event_output columns' do - db[:tasks] << { - id: 1, - state: 'finished', - type: 'something', - deployment_name: 'test-deployment', - timestamp: '2016-04-14 11:53:42', - description: 'description', - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:tasks].columns.include?(:result_output)).to be_truthy - expect(db[:tasks].columns.include?(:event_output)).to be_truthy - - expect(db[:tasks].map{|cp| cp[:result_output]}).to eq([nil]) - expect(db[:tasks].map{|cp| cp[:event_output]}).to eq([nil]) - end - - it 'ensures that fields allow texts longer than 65535 character' do - DBSpecHelper.migrate(migration_file) - - really_long_text = 'a' * 65536 - db[:tasks] << { - id: 1, - state: 'finished', - type: 'something', - deployment_name: 'test-deployment', - timestamp: '2016-04-14 11:53:42', - description: 'description', - result_output: really_long_text, - event_output: really_long_text - } - - expect(db[:tasks].map{|cp| cp[:result_output].length}).to eq([really_long_text.length]) - expect(db[:tasks].map{|cp| cp[:event_output].length}).to eq([really_long_text.length]) - end - end - -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20161209104649_add_context_id_to_tasks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20161209104649_add_context_id_to_tasks_spec.rb deleted file mode 100644 index 274f958ab48..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20161209104649_add_context_id_to_tasks_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'adding context id to tasks' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20161209104649_add_context_id_to_tasks.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'sets the default value of the context_id to empty string' do - db[:tasks] << {id: 1, state: 'alabama', timestamp: '2016-12-09 11:53:42', description: 'descr', type: 'type'} - - DBSpecHelper.migrate(migration_file) - - expect(db[:tasks].first[:context_id]).to eq('') - end - - context 'context length' do - before do - DBSpecHelper.skip_on_sqlite(self, 'string size is not limitable') - end - - it 'allows 64 chars in length' do - valid_context_id = "x" * 64 - - DBSpecHelper.migrate(migration_file) - db[:tasks] << {id: 1, state: 'alabama', timestamp: '2016-12-09 11:53:42', description: 'descr', type: 'type', context_id: valid_context_id} - - expect(db[:tasks].first[:context_id]).to eq(valid_context_id) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20161221151107_allow_null_instance_id_local_dns_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20161221151107_allow_null_instance_id_local_dns_spec.rb deleted file mode 100644 index 6ee11472a22..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20161221151107_allow_null_instance_id_local_dns_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'allowing null instance_id in local_dns_records' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20161221151107_allow_null_instance_id_local_dns.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'allows instance_id to be null' do - expect{ - db[:local_dns_records] << {id: 1, name: 'record1', ip: '123'} - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - db[:local_dns_records] << {id: 1, name: 'record1', ip: '123'} - expect(db[:local_dns_records].first[:instance_id]).to be_nil - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170104003158_add_agent_dns_version_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170104003158_add_agent_dns_version_spec.rb deleted file mode 100644 index 0d6be215973..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170104003158_add_agent_dns_version_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'adding context id to tasks' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170104003158_add_agent_dns_version.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'creates the table' do - DBSpecHelper.migrate(migration_file) - db[:agent_dns_versions] << { agent_id: 'abc', dns_version: 3 } - agent_dns_version = db[:agent_dns_versions].first - expect(agent_dns_version[:agent_id]).to eq('abc') - expect(agent_dns_version[:dns_version]).to eq(3) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170116235940_add_errand_runs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170116235940_add_errand_runs_spec.rb deleted file mode 100644 index cc2a6571f74..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170116235940_add_errand_runs_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_errands' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170116235940_add_errand_runs.rb' } - let(:instance) do - { - job: 'job', - index: 1, - deployment_id: 1, - cloud_properties: 'cloud_properties', - dns_records: 'dns_records', - spec_json: 'spec_json', - credentials_json: 'credentials_json', - state: 'running' - } - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { - name: 'deployment_with_teams', - link_spec_json: 'link_spec_json' - } - - db[:instances] << instance - end - - it 'creates the table with default value for ran_successfully' do - DBSpecHelper.migrate(migration_file) - db[:errand_runs] << {id: 1, instance_id: 1, successful_configuration_hash: 'some_hash', successful_packages_spec: 'long_json'} - - expect(db[:errand_runs].first[:instance_id]).to eq(1) - expect(db[:errand_runs].first[:successful]).to be_falsey - expect(db[:errand_runs].first[:successful_configuration_hash]).to eq('some_hash') - expect(db[:errand_runs].first[:successful_packages_spec]).to eq('long_json') - end - - it 'does not allow null values for instance' do - DBSpecHelper.migrate(migration_file) - expect { - db[:errand_runs] << {id: 1} - }.to raise_error Sequel::DatabaseError - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170119202003_update_sha1_column_sizes_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170119202003_update_sha1_column_sizes_spec.rb deleted file mode 100644 index b97bba9834d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170119202003_update_sha1_column_sizes_spec.rb +++ /dev/null @@ -1,155 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Changing column type to longtext' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170119202003_update_sha1_column_sizes.rb' } - let(:a_512_len_str) { 'b' * 512 } - let(:a_255_len_str) { 'a' * 255 } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'updates the column type' do - db[:releases] << {id: 1, name: 'test_release'} - - db[:packages] << { - release_id: 1, - name: 'test_package', - version: 'abcd1234', - dependency_set_json: '{}', - sha1: (a_255_len_str), - } - - db[:templates] << { - name: 'template_name', - release_id: 1, - version: 'abcd1234', - blobstore_id: '1', - package_names_json: '{}', - sha1: (a_255_len_str) - } - - db[:compiled_packages] << { - build: 1, - package_id: 1, - sha1: a_255_len_str, - blobstore_id: '1234abcd', - dependency_key: '{}', - dependency_key_sha1: a_255_len_str, - } - - db[:ephemeral_blobs] << { - blobstore_id: '1', - sha1: a_255_len_str, - created_at: Time.now - } - - db[:stemcells] << { - name: 'stemcell_name', - sha1: a_255_len_str, - version: '1', - cid: '1' - } - - db[:local_dns_blobs] << { - sha1: a_255_len_str, - blobstore_id: 'blob_id', - created_at: Time.now - } - - indexes_before = {} - db.tables.each do |t| - indexes_before[t] = db.indexes(t) - end - - DBSpecHelper.migrate(migration_file) - - expect(db[:packages].first[:sha1]).to eq(a_255_len_str) - expect(db[:templates].first[:sha1]).to eq(a_255_len_str) - expect(db[:compiled_packages].first[:sha1]).to eq(a_255_len_str) - expect(db[:compiled_packages].first[:dependency_key_sha1]).to eq(a_255_len_str) - expect(db[:ephemeral_blobs].first[:sha1]).to eq(a_255_len_str) - expect(db[:stemcells].first[:sha1]).to eq(a_255_len_str) - expect(db[:local_dns_blobs].first[:sha1]).to eq(a_255_len_str) - - db[:packages] << { - release_id: 1, - name: 'test_package', - version: 'abcd1235', - dependency_set_json: '{}', - sha1: a_512_len_str, - } - expect(db[:packages].where(sha1: a_512_len_str).count).to eq(1) - - db[:templates] << { - name: 'template_name', - release_id: 1, - version: 'abcd1235', - blobstore_id: '1', - package_names_json: '{}', - sha1: a_512_len_str - } - expect(db[:templates].where(sha1: a_512_len_str).count).to eq(1) - - db[:compiled_packages] << { - build: 1, - package_id: 1, - blobstore_id: '1234abcd', - dependency_key: 'blarg', - dependency_key_sha1: 'blarg_sha1', - sha1: a_512_len_str - } - expect(db[:compiled_packages].where(sha1: a_512_len_str).count).to eq(1) - - db[:ephemeral_blobs] << { - blobstore_id: '1', - sha1: a_512_len_str, - created_at: Time.now - } - expect(db[:ephemeral_blobs].where(sha1: a_512_len_str).count).to eq(1) - - db[:stemcells] << { - name: 'stemcell_name', - sha1: a_512_len_str, - version: '2', - cid: '1' - } - expect(db[:stemcells].where(sha1: a_512_len_str).count).to eq(1) - - db[:local_dns_blobs] << { - sha1: 'c' * 512, - blobstore_id: 'blob_id_2', - created_at: Time.now - } - expect(db[:local_dns_blobs].where(sha1: 'c' * 512).count).to eq(1) - - db.tables.each do |t| - if t == :local_dns_blobs - expect(db.indexes(t)).to be_empty - else - expect(db.indexes(t)).to eq(indexes_before[t]) - end - end - end - - it 'migrates when the index is not present' do - db.alter_table(:local_dns_blobs) do - drop_index [:blobstore_id, :sha1], name: 'blobstore_id_sha1_idx' - end - - db.tables.each do |t| - if t == :local_dns_blobs - expect(db.indexes(t)).to be_empty - end - end - - expect { DBSpecHelper.migrate(migration_file) }.to_not raise_exception - - db.tables.each do |t| - if t == :local_dns_blobs - expect(db.indexes(t)).to be_empty - end - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170203212124_add_variables_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170203212124_add_variables_spec.rb deleted file mode 100644 index 3b120cc8bfa..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170203212124_add_variables_spec.rb +++ /dev/null @@ -1,224 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_variables' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170203212124_add_variables.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - describe 'variable_sets table' do - before do - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_2'} - - DBSpecHelper.migrate(migration_file) - end - - it 'has a non null constraint for deployment_id' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { - db[:variable_sets] << {id: 100, created_at: Time.now} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'has a non null constraint for created_at' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { - db[:variable_sets] << {id: 100, deployment_id: 1} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'defaults deploy_success to false' do - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - expect(db[:variable_sets].first['deploy_success']).to be_falsey - end - - it 'has a foreign key association with deployments table' do - expect { - db[:variable_sets] << {id: 100, deployment_id: 646464, created_at: Time.now} - }.to raise_error Sequel::ForeignKeyConstraintViolation - end - - it 'cascades on deployment deletion' do - set_3_time = Time.now - - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 200, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 300, deployment_id: 2, created_at: set_3_time} - - expect(db[:variable_sets].count).to eq(5) # 2 were added during migration - - db[:deployments].where(id: 1).delete - expect(db[:variable_sets].count).to eq(2) - expect(db[:variable_sets].where(deployment_id: 1).count).to eq(0) - expect(db[:variable_sets].where(deployment_id: 2).count).to eq(2) - end - end - - describe 'variables table' do - before do - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_2'} - - DBSpecHelper.migrate(migration_file) - - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 200, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 300, deployment_id: 2, created_at: Time.now} - end - - it 'has a non null constraint for variable_id' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { - db[:variables] << {id: 1, variable_name: 'var_1', variable_set_id: 100} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'has a non null constraint for variable_name' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_set_id: 100} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'has a non null constraint for variable_set_id' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1'} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'cascades on variable_sets deletion' do - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100} - db[:variables] << {id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 100} - db[:variables] << {id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200} - - expect(db[:variables].count).to eq(3) - - db[:variable_sets].where(id: 100).delete - - expect(db[:variables].count).to eq(1) - expect(db[:variables].first).to eq({id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200}) - end - - it 'cascades on deployment deletion' do - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100} - db[:variables] << {id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 100} - db[:variables] << {id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 300} - - expect(db[:variables].count).to eq(3) - - db[:deployments].where(id: 1).delete - - expect(db[:variables].count).to eq(1) - expect(db[:variables].where(variable_set_id: 300).count).to eq(1) - end - - it 'has variable_set_id and variable_name unique constraint' do - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100} - - expect { - db[:variables] << {id: 2, variable_id: 'var_id_2', variable_name: 'var_1', variable_set_id: 100} - }.to raise_error Sequel::UniqueConstraintViolation - end - end - - describe 'adding variable sets to deployments' do - before do - db[:deployments] << {id: 123, name: 'deployment_1'} - end - - it 'adds a variable set to deployment' do - DBSpecHelper.migrate(migration_file) - - expect(db[:variable_sets].count).to eq(1) - expect(db[:variable_sets].first[:deployment_id]).to eq(123) - expect(db[:variable_sets].first[:created_at]).to_not be_nil - end - - end - - describe 'instances table' do - let(:instance_1) do - { - job: 'job_1', - index: 1, - deployment_id: 1, - state: 'running' - } - end - - let(:instance_2) do - { - job: 'job_2', - index: 1, - deployment_id: 2, - state: 'running' - } - end - - let(:instance_3) do - { - job: 'job_3', - index: 2, - deployment_id: 2, - state: 'running' - } - end - - before do - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_2'} - db[:deployments] << {id: 3, name: 'deployment_3'} - end - - it 'fills foreign key variable_set_id in instances table' do - db[:instances] << instance_1 - db[:instances] << instance_2 - db[:instances] << instance_3 - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(3) - - variable_set_1_id = db[:variable_sets].where(deployment_id: 1).first[:id] - dep_1_instances = db[:instances].where(deployment_id: 1).all - expect(dep_1_instances.count).to eq(1) - expect(dep_1_instances.first[:variable_set_id]).to eq(variable_set_1_id) - - variable_set_2_id = db[:variable_sets].where(deployment_id: 2).first[:id] - dep_2_instances = db[:instances].where(deployment_id: 2).all - expect(dep_2_instances.count).to eq(2) - dep_2_instances.each do |instance| - expect(instance[:variable_set_id]).to eq(variable_set_2_id) - end - - dep_3_instances = db[:instances].where(deployment_id: 3).all - expect(dep_3_instances.count).to eq(0) - end - - it 'does not allow null for variable_set_id column' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - DBSpecHelper.migrate(migration_file) - expect { - db[:instances] << {job: 'job', index: 1, deployment_id: 1, state: 'running'} - }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'has a foreign key association with variable_sets table' do - DBSpecHelper.migrate(migration_file) - expect { - db[:instances] << {job: 'job', index: 1, deployment_id: 1, state: 'running', variable_set_id: 999} - }.to raise_error Sequel::ForeignKeyConstraintViolation - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs_spec.rb deleted file mode 100644 index 0597cc24449..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170216194502_remove_blobstore_id_idx_from_local_dns_blobs_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Remove blobstore_id_idx' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170216194502_remove_blobstore_id_idx_from_local_dns_blobs.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'deletes it when it exists' do - db.alter_table(:local_dns_blobs) do - add_index :blobstore_id, unique: true, name: 'blobstore_id_idx' - end - - expect(db.indexes(:local_dns_blobs)).to have_key(:blobstore_id_idx) - DBSpecHelper.migrate(migration_file) - expect(db.indexes(:local_dns_blobs)).to be_empty - end - - it 'succeeds when it does not exist' do - expect(db.indexes(:local_dns_blobs)).to_not have_key(:blobstore_id_idx) - DBSpecHelper.migrate(migration_file) - expect(db.indexes(:local_dns_blobs)).to be_empty - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update_spec.rb deleted file mode 100644 index 8ccd79a49e1..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170217000000_variables_instance_table_foreign_key_update_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20170217000000_variables_instance_table_foreign_key_update' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170217000000_variables_instance_table_foreign_key_update.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - let(:constraints) { db.foreign_key_list(:instances).select { |v| v[:columns] == [:variable_set_id] } } - - it 'drops [variable_set_id] fkey on instances and adds named fkey' do - expect(constraints.size).to eq(1) - - expect(constraints[0][:columns]).to eq([:variable_set_id]) - expect(constraints[0][:table]).to eq(:variable_sets) - end - - it 'adds named fkey' do - DBSpecHelper.skip_on_sqlite(self, 'constraint name not shown') - - expect(constraints[0][:name]).to eq(:instance_table_variable_set_fkey) - expect(constraints[0][:key]).to eq([:id]) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170303175054_expand_template_json_column_lengths_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170303175054_expand_template_json_column_lengths_spec.rb deleted file mode 100644 index a1861c8233d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170303175054_expand_template_json_column_lengths_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20170303175054_expand_template_json_column_lengths' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170303175054_expand_template_json_column_lengths.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - end - - it 'expands the column lengths' do - db[:releases] << {id: 1, name: 'test_release'} - template_1 = { - name: 'template_name', - release_id: 1, - version: 'abcd1234', - blobstore_id: '1', - package_names_json: '{}', - sha1: "sha1", - provides_json: '{"provides": "json"}', - consumes_json: '{"consumes": "json"}' - } - db[:templates] << template_1 - - DBSpecHelper.migrate(migration_file) - - refreshed = db[:templates].first - template_1.keys.each do |key| - expect(refreshed[key]).to eq(template_1[key]) - end - - large_json = "{\"key\": \"#{"foo" * 1000}\"}" - db[:templates] << { - name: 'template_name_2', - release_id: 1, - version: 'abcd12345', - blobstore_id: '1', - package_names_json: '{}', - sha1: "sha1", - provides_json: large_json, - consumes_json: large_json - } - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170306215659_extend_vm_credentials_json_column_to_longtext_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170306215659_extend_vm_credentials_json_column_to_longtext_spec.rb deleted file mode 100644 index 797647a2d4f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170306215659_extend_vm_credentials_json_column_to_longtext_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20170306215659_extend_vm_credentials_json_column_to_longtext' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170306215659_expand_vms_json_column_lengths.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'expands the column lengths' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}'} - attrs = { - id: 1, - deployment_id: 1, - agent_id: 'fake-agent-id', - cid: 'fake-vm-cid', - env_json: 'fake-env-json', - trusted_certs_sha1: 'fake-trusted-certs-sha1', - credentials_json: 'fake-credentials-json' - } - db[:vms] << attrs - - DBSpecHelper.migrate(migration_file) - - expect(db[:vms].first).to eq(attrs) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records_spec.rb deleted file mode 100644 index 03fc412a25d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records_spec' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170320171505_add_id_group_az_network_deployment_columns_to_local_dns_records.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'add the new columns' do - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {deployment_id: 1, created_at: Time.now} - instance_spec_json_network = JSON.dump({ - 'deployment' => 'fake-deployment', - 'networks' => - { - 'fake-network' => {'ip' => '192.168.0.1' }, - 'other-network' => {'ip' => '192.168.1.2' } - }, - }) - db[:instances] << { - job: 'fake-instance-group', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: instance_spec_json_network, - } - instance_id = 1 - - db[:local_dns_records] << { - instance_id: instance_id, - name: 'dns.record.name1', - ip: '192.168.0.1', - } - - db[:local_dns_records] << { - instance_id: instance_id, - name: 'dns.record.name2', - ip: '192.168.1.2', - } - - db[:local_dns_records] << { - instance_id: nil, - name: 'tombstone-record', - ip: 'random-string', - } - - db[:local_dns_records] << { - instance_id: instance_id, - name: 'dns.record.name2', - ip: 'random-string', - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].all).to contain_exactly( - { - id: 1, - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: 'dns.record.name1', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - }, - { - id: 2, - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: 'dns.record.name2', - az: 'az1', - network: 'other-network', - deployment: 'fake-deployment', - ip: '192.168.1.2', - }, - { - id: 3, - instance_id: nil, - instance_group: nil, - name: 'tombstone-record', - az: nil, - network: nil, - deployment: nil, - ip: 'random-string', - }, - { - id: 4, - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: 'dns.record.name2', - az: 'az1', - network: '', - deployment: 'fake-deployment', - ip: 'random-string', - }, - ) - - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170321151400_add_writable_to_variable_set.rb_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170321151400_add_writable_to_variable_set.rb_spec.rb deleted file mode 100644 index 4013ccb5d58..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170321151400_add_writable_to_variable_set.rb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director -describe 'add_writable_to_variable_set' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170321151400_add_writable_to_variable_set.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_2'} - - DBSpecHelper.migrate(migration_file) - - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 200, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 300, deployment_id: 2, created_at: Time.now} - end - - it 'sets the writable field as false for migrated records' do - db[:variable_sets].map do |vs| - expect(vs[:writable]).to eq(false) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170328224049_associate_vm_info_with_vms_table_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170328224049_associate_vm_info_with_vms_table_spec.rb deleted file mode 100644 index d49b740d06f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170328224049_associate_vm_info_with_vms_table_spec.rb +++ /dev/null @@ -1,127 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'associate_vm_info_with_vms_table' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170328224049_associate_vm_info_with_vms_table.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {name: 'foo'} - db[:variable_sets] << {deployment_id: db[:deployments].first[:id], created_at: Time.now} - end - - it 'should reset vms table' do - expect(db.table_exists?('vms')).to be_truthy - db[:vms] << {agent_id: 1, deployment_id: db[:deployments].first[:id]} - - DBSpecHelper.migrate(migration_file) - expect(db.table_exists?('vms')).to be_truthy - - expect(db[:vms].all.length).to eq(0) - expect(db[:vms].columns).to contain_exactly(:id, :cid, :agent_id, :credentials_json, :trusted_certs_sha1, :instance_id) - end - - it 'drops the vm_id from instances table' do - expect(db[:instances].columns.include?(:vm_id)).to be_truthy - - DBSpecHelper.migrate(migration_file) - expect(db[:instances].columns.include?(:vm_id)).to be_falsey - end - - it 'has a unique contraint on the agent_id for the vm table' do - DBSpecHelper.migrate(migration_file) - - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - db[:vms] << {agent_id: 1, instance_id: 1} - expect { db[:vms] << {agent_id: 1, instance_id: 1} }.to raise_error(Sequel::UniqueConstraintViolation) - end - - it 'has a unique contraint on the cid for the vm table' do - DBSpecHelper.migrate(migration_file) - - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - db[:vms] << {cid: 1, instance_id: 1} - expect { db[:vms] << {cid: 1, instance_id: 1} }.to raise_error(Sequel::UniqueConstraintViolation) - end - - it 'has a foreign key to the instances table on the instances id for the vm table' do - DBSpecHelper.migrate(migration_file) - expect { db[:vms] << {instance_id: 999} }.to raise_error(Sequel::ForeignKeyConstraintViolation) - end - - it 'has a not null constraint on the instances id for the vm table' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - DBSpecHelper.migrate(migration_file) - expect { db[:vms] << {} }.to raise_error(Sequel::NotNullConstraintViolation) - end - - it 'defaults the trusted certs sha1 to the sha of an empty string for the vm table' do - DBSpecHelper.migrate(migration_file) - - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - db[:vms] << {cid: 1, instance_id: 1} - expect(db[:vms].all.first[:trusted_certs_sha1]).to eq('da39a3ee5e6b4b0d3255bfef95601890afd80709') - end - - it 'adds foreign key constraint on active_vm_id to instances' do - db[:variable_sets] << {deployment_id: db[:deployments].first[:id], created_at: Time.now} - - DBSpecHelper.migrate(migration_file) - expect { - db[:instances] << {id: 0, active_vm_id: 666, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - }.to raise_error Sequel::ForeignKeyConstraintViolation - end - - describe 'populating vms table' do - before do - db[:variable_sets] << {deployment_id: db[:deployments].first[:id], created_at: Time.now} - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 99, vm_cid: 100, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 2, job: 'blah', index: 1, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 100, vm_cid: 101, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 3, job: 'blah', index: 2, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 101, vm_cid: 102, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 4, job: 'blah', index: 3, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 103, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 5, job: 'blah', index: 4, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 102, vm_cid: 103, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - end - - it 'uses existing values in the instances table when instance has vm_cid' do - DBSpecHelper.migrate(migration_file) - expect(db[:vms].all).to contain_exactly( - {id: 1, instance_id: 1, agent_id: '99', cid: '100', credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'}, - {id: 2, instance_id: 2, agent_id: '100', cid: '101', credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'}, - {id: 3, instance_id: 3, agent_id: '101', cid: '102', credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'}, - {id: 4, instance_id: 5, agent_id: '102', cid: '103', credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - ) - - expect(db[:instances].where(id: 1).first[:active_vm_id]).to eq(1) - expect(db[:instances].where(id: 2).first[:active_vm_id]).to eq(2) - expect(db[:instances].where(id: 3).first[:active_vm_id]).to eq(3) - expect(db[:instances].where(id: 4).first[:active_vm_id]).to be_nil - expect(db[:instances].where(id: 5).first[:active_vm_id]).to eq(4) - end - end - - describe 'backing up important columns' do - before do - db[:variable_sets] << {deployment_id: db[:deployments].first[:id], created_at: Time.now} - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 99, vm_cid: 100, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 2, job: 'blah', index: 1, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 100, vm_cid: 101, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 3, job: 'blah', index: 2, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 101, vm_cid: 102, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 4, job: 'blah', index: 3, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 102, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - db[:instances] << {id: 5, job: 'blah', index: 4, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id: 103, vm_cid: 103, credentials_json: '{"foo":"bar"}', trusted_certs_sha1: 'some-trusted-cert-sha1'} - end - - it 'renames columns transferred to vms table (vm_cid, credentials_json, agent_id, trusted_certs_sha1)' do - DBSpecHelper.migrate(migration_file) - expect(db[:instances].all).to contain_exactly( - {id: 1, active_vm_id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id_bak: '99', vm_cid_bak: '100', credentials_json_bak: '{"foo":"bar"}', trusted_certs_sha1_bak: 'some-trusted-cert-sha1', resurrection_paused: false, uuid: nil, availability_zone: nil, cloud_properties: nil, compilation: false, bootstrap: false, dns_records: nil, spec_json: nil, update_completed: false, ignore: false }, - {id: 2, active_vm_id: 2, job: 'blah', index: 1, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id_bak: '100', vm_cid_bak: '101', credentials_json_bak: '{"foo":"bar"}', trusted_certs_sha1_bak: 'some-trusted-cert-sha1', resurrection_paused: false, uuid: nil, availability_zone: nil, cloud_properties: nil, compilation: false, bootstrap: false, dns_records: nil, spec_json: nil, update_completed: false, ignore: false }, - {id: 3, active_vm_id: 3, job: 'blah', index: 2, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id_bak: '101', vm_cid_bak: '102', credentials_json_bak: '{"foo":"bar"}', trusted_certs_sha1_bak: 'some-trusted-cert-sha1', resurrection_paused: false, uuid: nil, availability_zone: nil, cloud_properties: nil, compilation: false, bootstrap: false, dns_records: nil, spec_json: nil, update_completed: false, ignore: false }, - {id: 4, active_vm_id: nil, job: 'blah', index: 3, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id_bak: '102', vm_cid_bak: nil, credentials_json_bak: '{"foo":"bar"}', trusted_certs_sha1_bak: 'some-trusted-cert-sha1', resurrection_paused: false, uuid: nil, availability_zone: nil, cloud_properties: nil, compilation: false, bootstrap: false, dns_records: nil, spec_json: nil, update_completed: false, ignore: false }, - {id: 5, active_vm_id: 4, job: 'blah', index: 4, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running', agent_id_bak: '103', vm_cid_bak: '103', credentials_json_bak: '{"foo":"bar"}', trusted_certs_sha1_bak: 'some-trusted-cert-sha1', resurrection_paused: false, uuid: nil, availability_zone: nil, cloud_properties: nil, compilation: false, bootstrap: false, dns_records: nil, spec_json: nil, update_completed: false, ignore: false }, - ) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170331171657_remove_active_vm_id_from_instances_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170331171657_remove_active_vm_id_from_instances_spec.rb deleted file mode 100644 index 025de62bef8..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170331171657_remove_active_vm_id_from_instances_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'remove_active_vm_id_from_instances' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170331171657_remove_active_vm_id_from_instances.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:deployments] << {name: 'foo'} - db[:variable_sets] << {deployment_id: db[:deployments].first[:id], created_at: Time.now} - end - - it 'drops the active_vm_id from instances table' do - expect(db[:instances].columns.include?(:active_vm_id)).to be_truthy - - DBSpecHelper.migrate(migration_file) - expect(db[:instances].columns.include?(:active_vm_id)).to be_falsey - end - - it 'adds is_active column to vms table' do - expect(db[:vms].columns.include?(:active)).to be_falsey - - DBSpecHelper.migrate(migration_file) - - expect(db[:vms].columns.include?(:active)).to be_truthy - end - - it 'sets all existing vms to be active true' do - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - db[:vms] << {id: 1, instance_id: 1} - - DBSpecHelper.migrate(migration_file) - - expect(db[:vms].first[:active]).to eq(true) - end - - it 'sets active to default to false' do - DBSpecHelper.migrate(migration_file) - db[:instances] << {id: 1, job: 'blah', index: 0, deployment_id: db[:deployments].first[:id], variable_set_id: db[:variable_sets].first[:id], state: 'running'} - db[:vms] << {id: 2, instance_id: 1} - - expect(db[:vms].first[:active]).to eq(false) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables_spec.rb deleted file mode 100644 index 53546d0b98a..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170405144414_add_cross_deployment_links_support_for_variables_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add cross deployment link support for variables' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170405144414_add_cross_deployment_links_support_for_variables.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - describe 'alter variables table' do - before do - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_2'} - - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - db[:variable_sets] << {id: 200, deployment_id: 2, created_at: Time.now} - - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 100} - db[:variables] << {id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 100} - db[:variables] << {id: 3, variable_id: 'var[]_id_3', variable_name: 'var_3', variable_set_id: 200} - - DBSpecHelper.migrate(migration_file) - - expect(db[:variables].count).to eq(3) - end - - it 'adds local boolean column and defaults it to true for existing variables' do - db[:variables].each do |variable| - expect(variable[:is_local]).to be_truthy - end - end - - it 'adds provider_deployment text column and defaults it to an empty string for existing variables' do - db[:variables].each do |variable| - expect(variable[:provider_deployment]).to be_empty - end - end - - it 'keeps the foreign key constraint with the variable set table' do - expect { - db[:variables] << {id: 999, variable_id: 'whatever', variable_name: 'another_whatever', variable_set_id: 999} - }.to raise_error Sequel::ForeignKeyConstraintViolation - - expect { - db[:variables] << {id: 999, variable_id: 'whatever', variable_name: 'another_whatever', variable_set_id: nil} - }.to raise_error Sequel::NotNullConstraintViolation - - expect { - db[:variables] << {id: 999, variable_id: 'whatever', variable_name: 'another_whatever', variable_set_id: 100} - }.to_not raise_error - end - - it 'keeps correct foreign key constraints with variable set table after migration' do - expect(db[:variables].where(id: 1).first[:variable_set_id]).to eq(100) - expect(db[:variables].where(id: 2).first[:variable_set_id]).to eq(100) - expect(db[:variables].where(id: 3).first[:variable_set_id]).to eq(200) - end - - it 'keeps the cascade property when deleting variable sets' do - db[:variable_sets].where(id: 100).delete - - expect(db[:variables].count).to eq(1) - expect(db[:variables].where(variable_set_id: 100).count).to eq(0) - expect(db[:variables].where(variable_set_id: 200).count).to eq(1) - end - - it 'adds a new unique index for :variable_set_id, :variable_name, and :provider_deployment' do - db[:variables] << {id: 5, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200, provider_deployment: 'test'} - expect { - db[:variables] << {id: 6, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200, provider_deployment: 'test'} - }.to raise_error Sequel::UniqueConstraintViolation - end - - it 'removes unique index :variable_set_id and :variable_name' do - db[:variables] << {id: 5, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200, is_local: true, provider_deployment: 'some_deployment'} - expect { - db[:variables] << {id: 6, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 200, is_local: true, provider_deployment: 'some_other_deployment'} - }.to_not raise_error - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name_spec.rb deleted file mode 100644 index dcc9d8682cb..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170405181126_backfill_local_dns_records_and_drop_name_spec.rb +++ /dev/null @@ -1,228 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'backfill_local_dns_records_and_drop_name' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170405181126_backfill_local_dns_records_and_drop_name.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {deployment_id: 1, created_at: Time.now} - end - - it 'drops the name from local_dns_records table and backfills data' do - DBSpecHelper.skip_on_sqlite(self, 'auto-increment is not predictable') - - instance1_spec_json = JSON.dump( - { - 'deployment' => 'fake-deployment', - 'networks' => - { - 'fake-network' => {'ip' => '192.168.0.1'}, - 'other-network' => {'ip' => '192.168.1.2'} - }, - } - ) - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid1', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: instance1_spec_json, - } - instance_id = 1 - - db[:local_dns_records] << { - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: 'uuid1.fake-instance-group.fake-network.fake-deployment.name1', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - } - - db[:local_dns_records] << { - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: '1.fake-instance-group.fake-network.fake-deployment.name1', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - } - - db[:local_dns_records] << { - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: 'uuid1.fake-instance-group.other-network.fake-deployment.name1', - az: 'az1', - network: 'other-network', - deployment: 'fake-deployment', - ip: '192.168.1.2', - } - - db[:local_dns_records] << { - instance_id: instance_id, - instance_group: 'fake-instance-group', - name: '1.fake-instance-group.other-network.fake-deployment.name1', - az: 'az1', - network: 'other-network', - deployment: 'fake-deployment', - ip: '192.168.1.2', - } - - instance2_spec_json = JSON.dump( - { - 'deployment' => 'fake-deployment', - 'networks' => - { - 'fake-network' => {'ip' => '192.168.0.2'}, - 'other-network' => {'ip' => '192.168.1.3'} - }, - } - ) - instance2_id = 2 - - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid2', - index: 2, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: instance2_spec_json, - } - - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid3', - index: 3, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: 'invalid json', - } - - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid4', - index: 4, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: JSON.dump( - { - 'deployment' => 'fake-deployment', - 'networks' => - { - 'fake-network' => {'ip' => '192.168.5.2'}, - 'other-network' => nil - }, - }) - } - - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid5', - index: 5, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: JSON.dump( - { - 'deployment' => 'fake-deployment', - 'networks' => nil - }) - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].all).to contain_exactly( - { - id: 5, - instance_id: instance_id, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - }, - { - id: 6, - instance_id: instance_id, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'other-network', - deployment: 'fake-deployment', - ip: '192.168.1.2', - }, - { - id: 7, - instance_id: instance2_id, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.2', - }, - { - id: 8, - instance_id: instance2_id, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'other-network', - deployment: 'fake-deployment', - ip: '192.168.1.3', - }, - { - id: 9, - instance_id: 4, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.5.2', - } - ) - end - - it 'drops the cascade delete so developers know to delete the local_dns_records properly, and ensuring tombstones' do - instance1_spec_json = JSON.dump( - { - 'deployment' => 'fake-deployment', - 'networks' => - { - 'fake-network' => {'ip' => '192.168.0.1'}, - 'other-network' => {'ip' => '192.168.1.2'} - }, - } - ) - - db[:instances] << { - job: 'fake-instance-group', - uuid: 'uuid1', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: instance1_spec_json, - } - - DBSpecHelper.migrate(migration_file) - - expect{ - db[:instances].delete - }.to raise_error(Sequel::ForeignKeyConstraintViolation) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records_spec.rb deleted file mode 100644 index 509f3309491..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170412205032_add_agent_id_and_domain_name_to_local_dns_records_spec.rb +++ /dev/null @@ -1,115 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'add_agent_id_and_domain_name_to_local_dns_records_spec' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170412205032_add_agent_id_and_domain_name_to_local_dns_records.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {deployment_id: 1, created_at: Time.now} - end - - it 'ignores tombstones' do - db[:local_dns_records] << { - ip: 'd03b0d55-7a16-47d4-8eab-b1ebea8629cd-tombstone', - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].first).to eq({ - id: 1, - instance_id: nil, - instance_group: nil, - az: nil, - network: nil, - deployment: nil, - ip: 'd03b0d55-7a16-47d4-8eab-b1ebea8629cd-tombstone', - agent_id: nil, - domain: nil, - }) - end - - it 'ignores instances which do not currently have a vm' do - db[:instances] << { - id: 1, - job: 'fake-instance-group', - uuid: 'uuid1', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: '{}', - } - - db[:local_dns_records] << { - instance_id: 1, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].first).to eq({ - id: 1, - instance_id: 1, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - agent_id: nil, - domain: nil, - }) - end - - it 'adds domain name and agent id to the local_dns_records table' do - db[:instances] << { - id: 1, - job: 'fake-instance-group', - uuid: 'uuid1', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: '{}', - } - - db[:vms] << { - id: 1, - instance_id: 1, - agent_id: 'fake-agent-uuid1', - active: true, - } - - db[:local_dns_records] << { - instance_id: 1, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - } - - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].first).to eq({ - id: 1, - instance_id: 1, - instance_group: 'fake-instance-group', - az: 'az1', - network: 'fake-network', - deployment: 'fake-deployment', - ip: '192.168.0.1', - agent_id: 'fake-agent-uuid1', - domain: nil, - }) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170427194511_add_runtime_config_name_support_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170427194511_add_runtime_config_name_support_spec.rb deleted file mode 100644 index c467d89222a..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170427194511_add_runtime_config_name_support_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Add Runtime Config Name Support' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170427194511_add_runtime_config_name_support.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'adds the name column to the runtime config table and defaults it to empty' do - db[:runtime_configs] << {id: 100, properties: 'I am alive', created_at: Time.now} - db[:runtime_configs] << {id: 200, properties: 'I am alive, too', created_at: Time.now} - - DBSpecHelper.migrate(migration_file) - - expect(db[:runtime_configs].where(id: 100).first[:name]).to eq('') - expect(db[:runtime_configs].where(id: 200).first[:name]).to eq('') - end - - it 'supports adding names to runtime config' do - DBSpecHelper.migrate(migration_file) - db[:runtime_configs] << {id: 100, properties: 'I am alive', name: 'CUSTOM_CONFIG_1', created_at: Time.now} - db[:runtime_configs] << {id: 200, properties: 'I am alive', created_at: Time.now} - - expect(db[:runtime_configs].where(id: 100).first[:name]).to eq('CUSTOM_CONFIG_1') - expect(db[:runtime_configs].where(id: 200).first[:name]).to eq('') - end - - it 'does NOT support a null value for name' do - DBSpecHelper.migrate(migration_file) - - expect{ - db[:runtime_configs] << {id: 100, properties: 'I am alive', name: nil, created_at: Time.now} - }.to raise_error Sequel::NotNullConstraintViolation - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170503205545_change_id_local_dns_to_bigint_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170503205545_change_id_local_dns_to_bigint_spec.rb deleted file mode 100644 index 3222b189ee8..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170503205545_change_id_local_dns_to_bigint_spec.rb +++ /dev/null @@ -1,121 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'change id from int to bigint on local_dns_blob', truncation: true do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170503205545_change_id_local_dns_to_bigint.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - def can_insert_value_with_bigint(table, record, where_clause) - db[table] << record - expect(db[table].where(where_clause)).to_not be_empty - end - - it 'increments id on local_dns_records from original series' do - db[:local_dns_records] << {ip: '123'} - former_max_id = db[:local_dns_records].all[-1][:id] - - DBSpecHelper.migrate(migration_file) - - db[:local_dns_records] << {ip: '456'} - new_max_id = db[:local_dns_records].all[-1][:id] - expect(new_max_id > former_max_id).to be_truthy - end - - it 'local_dns_records should change the type from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:local_dns_records] << {id: 8589934592, ip: '987'} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:local_dns_records].first[:id] == 8589934592 - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - - can_insert_value_with_bigint(:local_dns_records, {id: 9223372036854775807, ip: '123'}, Sequel.lit('id = 9223372036854775807')) - end - - it 'increments id on local_dns_blobs from original series' do - db[:local_dns_blobs] << {blobstore_id: '123', sha1: 'sha1', created_at: Time.now, version: 2} - former_max_id = db[:local_dns_blobs].all[-1][:id] - - DBSpecHelper.migrate(migration_file) - - db[:local_dns_blobs] << {blobstore_id: '456', sha1: 'sha1', created_at: Time.now, version: 3} - new_max_id = db[:local_dns_blobs].all[-1][:id] - expect(new_max_id > former_max_id).to be_truthy - end - - it 'local_dns_blobs should change the type of id from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:local_dns_blobs] << {id: 8589934592, blobstore_id: '123', sha1: 'sha1', created_at: Time.now, version: 2} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:local_dns_blobs].first[:id] == 8589934592 - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - can_insert_value_with_bigint(:local_dns_blobs, {id: 9223372036854775807, blobstore_id: '123', sha1: 'sha1', created_at: Time.now, version: 3}, Sequel.lit('id = 9223372036854775807')) - end - - it 'local_dns_blobs should change the type of version from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:local_dns_blobs] << {version: 8589934592, blobstore_id: '123', sha1: 'sha1', created_at: Time.now} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:local_dns_blobs].first[:version] == 8589934592 - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - can_insert_value_with_bigint(:local_dns_blobs, {version: 9223372036854775807, blobstore_id: '123', sha1: 'sha1', created_at: Time.now}, Sequel.lit('version = 9223372036854775807')) - end - - it 'agent_dns_versions should change the type of dns_version from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:agent_dns_versions] << {dns_version: 8589934592, agent_id: '123'} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:agent_dns_versions].first[:dns_version] == 8589934592 - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - can_insert_value_with_bigint(:agent_dns_versions, {dns_version: 9223372036854775807, agent_id: '456'}, Sequel.lit('dns_version = 9223372036854775807')) - end - - it 'increments id on agent_dns_versions from original series' do - db[:agent_dns_versions] << {agent_id: '123', dns_version: 2} - former_max_id = db[:agent_dns_versions].all[-1][:id] - - DBSpecHelper.migrate(migration_file) - - db[:agent_dns_versions] << {agent_id: '456', dns_version: 3} - new_max_id = db[:agent_dns_versions].all[-1][:id] - expect(new_max_id > former_max_id).to be_truthy - end - - it 'agent_dns_versions should change the type of id from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:agent_dns_versions] << {id: 8589934592, agent_id: '123', dns_version: 2} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:agent_dns_versions].first[:id] == 8589934592 - }.to raise_error Sequel::DatabaseError - - DBSpecHelper.migrate(migration_file) - can_insert_value_with_bigint(:agent_dns_versions, {id: 9223372036854775807, agent_id: '456', dns_version: 3}, Sequel.lit('id = 9223372036854775807')) - end - end -end - - diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170510154449_add_multi_runtime_config_support_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170510154449_add_multi_runtime_config_support_spec.rb deleted file mode 100644 index 929f12b8256..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170510154449_add_multi_runtime_config_support_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Add Multi-Runtime-Config Support' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170510154449_add_multi_runtime_config_support.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:runtime_configs] << {id: 100, properties: 'version_1', created_at: Time.now} - db[:runtime_configs] << {id: 200, properties: 'version_2', created_at: Time.now} - db[:runtime_configs] << {id: 300, properties: 'version_3', created_at: Time.now} - - db[:deployments] << {id: 1, name: 'deployment_1', runtime_config_id: 100} - db[:deployments] << {id: 2, name: 'deployment_2', runtime_config_id: 100} - db[:deployments] << {id: 3, name: 'deployment_3', runtime_config_id: 200} - db[:deployments] << {id: 4, name: 'deployment_4'} - end - - it 'should migrate existing deployment records to reflect many-to-many relationship between deployments & runtime config' do - DBSpecHelper.migrate(migration_file) - - expect(db[:deployments_runtime_configs].all).to contain_exactly( - {:deployment_id=>1, :runtime_config_id=>100}, - {:deployment_id=>2, :runtime_config_id=>100}, - {:deployment_id=>3, :runtime_config_id=>200} - ) - end - - it 'removes runtime config foreign key column and reference in the deployment table' do - DBSpecHelper.migrate(migration_file) - - expect(db[:deployments].all.count).to eq(4) - db[:deployments].all.each do |deployment| - expect(deployment.key?(:runtime_config_id)).to be_falsey - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170510190908_alter_ephemeral_blobs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170510190908_alter_ephemeral_blobs_spec.rb deleted file mode 100644 index 294c0ca4efb..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170510190908_alter_ephemeral_blobs_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'renames table' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170510190908_alter_ephemeral_blobs.rb' } - let(:created_at_time) { Time.now.utc } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - context 'existing ephemeral blobs' do - it 'increments id on local_dns_records from original series' do - db[:ephemeral_blobs] << {blobstore_id: 'test1', sha1: 'fake-sha1', created_at: created_at_time} - expect(db[:ephemeral_blobs].all.count).to eq(1) - - DBSpecHelper.migrate(migration_file) - - record = db[:blobs].all[0] - expect(record[:blobstore_id]).to eq('test1') - expect(record[:sha1]).to eq('fake-sha1') - expect(record[:created_at]).to_not be_nil - - db[:blobs] << {blobstore_id: 'test2', sha1: 'fake-sha2', created_at: created_at_time} - expect(db[:blobs].count).to eq(2) - - expect { db[:ephemeral_blobs].all }.to raise_exception(Sequel::DatabaseError) - end - - it 'backfills ephemeral blobs as compiled releases' do - db[:ephemeral_blobs] << {blobstore_id: 'test1', sha1: 'fake-sha1', created_at: created_at_time} - expect(db[:ephemeral_blobs].all.count).to eq(1) - - DBSpecHelper.migrate(migration_file) - - record = db[:blobs].all[0] - expect(record[:type]).to eq('compiled-release') - end - end - - context 'dns blobs' do - it 'imports existing blobs' do - db[:local_dns_blobs] << {blobstore_id: 'test1', sha1: 'fake-sha1', version: '2', created_at: created_at_time} - pre_migration_record = db[:local_dns_blobs].all[0] - - DBSpecHelper.migrate(migration_file) - - post_migration_record = db[:blobs].all[0] - expect(post_migration_record[:blobstore_id]).to eq(pre_migration_record[:blobstore_id]) - expect(post_migration_record[:sha1]).to eq(pre_migration_record[:sha1]) - expect(post_migration_record[:created_at]).to eq(pre_migration_record[:created_at]) - expect(post_migration_record[:type]).to eq('dns') - - post_migration_dns_blob = db[:local_dns_blobs].all[0] - expect(post_migration_dns_blob[:blob_id]).to eq(post_migration_record[:id]) - - # Dropping these columns, so hash lookup gives nil result - expect(post_migration_dns_blob[:blobstore_id]).to be_nil - expect(post_migration_dns_blob[:sha1]).to be_nil - end - - it 'does not allow null blob_id' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - DBSpecHelper.migrate(migration_file) - - expect { db[:local_dns_blobs] << { version: '2', created_at: created_at_time } } - .to raise_error Sequel::NotNullConstraintViolation - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170606225018_add_cpi_to_cloud_records_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170606225018_add_cpi_to_cloud_records_spec.rb deleted file mode 100644 index 66ee3248f49..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170606225018_add_cpi_to_cloud_records_spec.rb +++ /dev/null @@ -1,130 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20170606225018_add_cpi_to_cloud_records.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170606225018_add_cpi_to_cloud_records.rb' } - let(:created_at_time) { Time.now } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - describe 'backfilling orphaned_disks data' do - it 'cpi is set when az is present in latest cloud config' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', availability_zone: 'z1', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "azs:\n- name: z1\n cpi: my-cpi", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to eq('z1') - expect(subject[:cpi]).to eq('my-cpi') - end - - it 'cpi is empty when az is not present in latest cloud config' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', availability_zone: 'z2', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "azs:\n- name: z1\n cpi: my-cpi", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to eq('z2') - expect(subject[:cpi]).to eq('') - end - - it 'cpi is empty when az does not configure cpi in latest cloud config' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', availability_zone: 'z1', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "azs:\n- name: z1\n cpi: my-cpi\n- name: z2\n cpi: my-cpi", created_at: created_at_time } - db[:cloud_configs] << { properties: "azs:\n- name: z1\n- name: z2\n cpi: my-cpi", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to eq('z1') - expect(subject[:cpi]).to eq('') - end - - it 'cpi is empty when az is not specified' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "azs:\n- name: z1\n- name: z2\n cpi: my-cpi", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to be_nil - expect(subject[:cpi]).to eq('') - end - - it 'cpi is empty when there is no cloud config' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', disk_cid: 'disk-12345678', created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to be_nil - expect(subject[:cpi]).to eq('') - end - - it 'does not crash migration if cloud config is malformed' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', availability_zone: 'z1', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "{something", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to eq('z1') - expect(subject[:cpi]).to eq('') - end - - it 'cpi is empty when there are no azs defined in cloud config' do - db[:orphan_disks] << { deployment_name: 'test-deployment', instance_name: 'test-instance', availability_zone: 'z1', disk_cid: 'disk-12345678', created_at: created_at_time } - db[:cloud_configs] << { properties: "networks: []", created_at: created_at_time } - - DBSpecHelper.migrate(migration_file) - - subject = db[:orphan_disks].all[0] - expect(subject[:availability_zone]).to eq('z1') - expect(subject[:cpi]).to eq('') - end - end - - describe 'backfilling vms data' do - it 'sets cpi according to versioned cloud config via instance and deployment' do - db[:cloud_configs] << { properties: "azs:\n- name: z1\n cpi: my-cpi", created_at: created_at_time } - db[:deployments] << { name: 'deployment', cloud_config_id: 1 } - db[:variable_sets] << { created_at: Time.now, deployment_id: 1 } - db[:instances] << { availability_zone: 'z1', deployment_id: 1, state: 'running', job: 'instance-group-1', index: 0, variable_set_id: 1 } - db[:vms] << { instance_id: 1 } - - DBSpecHelper.migrate(migration_file) - - subject = db[:vms].all[0] - expect(subject[:cpi]).to eq('my-cpi') - end - - it 'leaves cpi empty when there are no cloud configs' do - db[:deployments] << { name: 'deployment' } - db[:variable_sets] << { created_at: Time.now, deployment_id: 1 } - db[:instances] << { availability_zone: 'z1', deployment_id: 1, state: 'running', job: 'instance-group-1', index: 0, variable_set_id: 1 } - db[:vms] << { instance_id: 1 } - - DBSpecHelper.migrate(migration_file) - - subject = db[:vms].all[0] - expect(subject[:cpi]).to eq('') - end - - it 'leaves cpi empty when the instance does not have an az associated with it' do - db[:cloud_configs] << { properties: "azs:\n- name: z1\n cpi: my-cpi", created_at: created_at_time } - db[:deployments] << { name: 'deployment', cloud_config_id: 1 } - db[:variable_sets] << { created_at: Time.now, deployment_id: 1 } - db[:instances] << { deployment_id: 1, state: 'running', job: 'instance-group-1', index: 0, variable_set_id: 1 } - db[:vms] << { instance_id: 1 } - - DBSpecHelper.migrate(migration_file) - - subject = db[:vms].all[0] - expect(subject[:cpi]).to eq('') - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170607182149_add_task_id_to_locks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170607182149_add_task_id_to_locks_spec.rb deleted file mode 100644 index 05d8b173ce7..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170607182149_add_task_id_to_locks_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Add task id to locks' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170607182149_add_task_id_to_locks.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'adds the task_id column to locks table and defaults it to empty' do - db[:locks] << {id: 100, name: 'lock1', uid: 'uuid-1', expired_at: Time.now} - db[:locks] << {id: 200, name: 'lock2', uid: 'uuid-2', expired_at: Time.now} - - DBSpecHelper.migrate(migration_file) - - expect(db[:locks].where(id: 100).first[:task_id]).to eq('') - expect(db[:locks].where(id: 200).first[:task_id]).to eq('') - end - - it 'supports adding task ids to lock' do - DBSpecHelper.migrate(migration_file) - db[:locks] << {id: 100, name: 'lock1', uid: 'uuid-1', task_id: "task_1", expired_at: Time.now} - db[:locks] << {id: 200, name: 'lock2', uid: 'uuid-2', expired_at: Time.now} - - expect(db[:locks].where(id: 100).first[:task_id]).to eq('task_1') - expect(db[:locks].where(id: 200).first[:task_id]).to eq('') - end - - it 'does NOT support a null value for task_id' do - DBSpecHelper.migrate(migration_file) - - expect{ - db[:locks] << {id: 100, name: 'lock1', uid: 'uuid-1', task_id: nil, expired_at: Time.now} - }.to raise_error Sequel::NotNullConstraintViolation - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170612013910_add_created_at_to_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170612013910_add_created_at_to_vms_spec.rb deleted file mode 100644 index 43489474f86..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170612013910_add_created_at_to_vms_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe 'Add created_at to vms table' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170612013910_add_created_at_to_vms.rb' } - let(:created_at_time) { Time.now.utc } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {deployment_id: 1, created_at: created_at_time} - db[:instances] << { - id: 1, - job: 'fake-instance-group', - uuid: 'uuid1', - index: 1, - deployment_id: 1, - state: 'started', - availability_zone: 'az1', - variable_set_id: 1, - spec_json: '{}', - } - end - - it 'adds the created_at column to the vms table and defaults it to nil' do - db[:vms] << { - id: 1, - instance_id: 1, - agent_id: 'fake-agent-uuid1', - active: true - } - expect(db[:vms].columns.include?(:created_at)).to be_falsey - DBSpecHelper.migrate(migration_file) - expect(db[:vms].columns.include?(:created_at)).to be_truthy - expect(db[:vms].where(id: 1).first[:created_at]).to be_nil - end - - it 'supports adding created_at to vms' do - DBSpecHelper.migrate(migration_file) - db[:vms] << { - id: 1, - instance_id: 1, - agent_id: 'fake-agent-uuid1', - active: true, - created_at: created_at_time - } - - expect(db[:vms].where(id: 1).first[:created_at]).not_to be_nil - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170616173221_remove_users_table_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170616173221_remove_users_table_spec.rb deleted file mode 100644 index b4c200d6888..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170616173221_remove_users_table_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'drop users' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170616173221_remove_users_table.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'drops them' do - db[:users] << {username: 'short-timer', password: 's3kr3t!'} - - DBSpecHelper.migrate(migration_file) - - expect(db.tables).to_not include(:users) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170616185237_migrate_spec_json_links_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170616185237_migrate_spec_json_links_spec.rb deleted file mode 100644 index 97e8716e454..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170616185237_migrate_spec_json_links_spec.rb +++ /dev/null @@ -1,199 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'migrate_spec_json_links' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170616185237_migrate_spec_json_links.rb' } - let(:created_at_time) { Time.now.utc } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}'} - db[:variable_sets] << {id: 100, deployment_id: 1, created_at: Time.now} - db[:instances] << { - id: 1, - job: 'fake-job', - index: 1, - deployment_id: 1, - variable_set_id: 100, - state: 'started', - spec_json: pre_migrated_spec_json - } - - DBSpecHelper.migrate(migration_file) - - end - - context 'when links exist for an instance' do - let(:pre_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [ - { 'name': 'simple_job_1' }, - { 'name': 'simple_job_2' }, - ], - }, - 'links': { - 'simple_link_name_1': { - 'name': 'simple_1', - }, - 'simple_link_name_2': { - 'name': 'simple_2', - }, - }, - }.to_json - end - let(:post_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [ - { 'name': 'simple_job_1' }, - { 'name': 'simple_job_2' }, - ], - }, - 'links': { - 'simple_job_1': { - 'simple_link_name_1': { - 'name': 'simple_1', - }, - 'simple_link_name_2': { - 'name': 'simple_2', - }, - }, - 'simple_job_2': { - 'simple_link_name_1': { - 'name': 'simple_1', - }, - 'simple_link_name_2': { - 'name': 'simple_2', - }, - }, - }, - }.to_json - end - - it 'should move links under each own job section' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(post_migrated_spec_json) - end - end - - context 'when links are empty for an instance' do - let(:pre_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [ - { 'name': 'simple_job_1' }, - { 'name': 'simple_job_2' }, - ], - }, - 'links': {}, - }.to_json - end - let(:post_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [ - { 'name': 'simple_job_1' }, - { 'name': 'simple_job_2' }, - ], - }, - 'links': { - 'simple_job_1': {}, - 'simple_job_2': {}, - }, - }.to_json - end - it 'should move links under each own job section' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(post_migrated_spec_json) - end - end - - context 'when links key is NOT defined in spec_json' do - let(:pre_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [ - { 'name': 'simple_job_1' }, - { 'name': 'simple_job_2' }, - ], - }, - }.to_json - end - it 'should NOT modify spec_json' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(pre_migrated_spec_json) - end - end - - context 'when spec_json is empty it should NOT raise an error' do - let(:pre_migrated_spec_json) { nil } - - it 'should NOT modify spec_json' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(nil) - end - end - - context 'when jobs/templates are empty for an instance' do - let(:pre_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - 'templates': [], - }, - 'links': { - 'simple_link_name_1': { - 'name': 'simple_1', - }, - 'simple_link_name_2': { - 'name': 'simple_2', - }, - }, - }.to_json - end - - it 'should NOT modify spec_json' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(pre_migrated_spec_json) - end - end - - context 'when jobs/templates key is NOT defined for an instance' do - let(:pre_migrated_spec_json) do - { - 'deployment': 'simple-deployment', - 'job': { - 'name': 'provider_instance_group', - }, - 'links': { - 'simple_link_name_1': { - 'name': 'simple_1', - }, - 'simple_link_name_2': { - 'name': 'simple_2', - }, - }, - }.to_json - end - - it 'should NOT modify spec_json' do - expect(db[:instances].count).to eq(1) - expect(db[:instances].all[0][:spec_json]).to eq(pre_migrated_spec_json) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170628221611_add_canonical_az_names_and_ids_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170628221611_add_canonical_az_names_and_ids_spec.rb deleted file mode 100644 index d736627cade..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170628221611_add_canonical_az_names_and_ids_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add_canonical_az_names_and_ids' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170628221611_add_canonical_az_names_and_ids.rb' } - let(:created_at_time) { Time.now.utc } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - it 'does not allow duplicate entries' do - db[:local_dns_encoded_azs] << {name: 'something'} - - expect { - db[:local_dns_encoded_azs] << {name: 'something'} - }.to raise_error Sequel::UniqueConstraintViolation - end - - it 'does not allow null entries' do - expect { - db[:local_dns_encoded_azs] << {name: nil} - }.to raise_error Sequel::NotNullConstraintViolation - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170705204352_add_cpi_to_disks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170705204352_add_cpi_to_disks_spec.rb deleted file mode 100644 index 842062f013b..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170705204352_add_cpi_to_disks_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20170705204352_add_cpi_to_disks.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170705204352_add_cpi_to_disks.rb' } - let(:created_at_time) { Time.now } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - describe 'backfilling persistent_disks data' do - let(:cloud_config_properties) do - {} - end - - before do - db[:cloud_configs] << { properties: cloud_config_properties.to_yaml, created_at: created_at_time, id: 37 } - db[:deployments] << { name: 'fake-deployment', id: 42 } - db[:variable_sets] << { id: 57, deployment_id: 42, created_at: created_at_time } - db[:instances] << { id: 123, availability_zone: 'z1', deployment_id: 42, job: 'instance_job', index: 23, state: 'started', variable_set_id: 57 } - db[:persistent_disks] << { disk_cid: 'disk-12345678', instance_id: 123 } - end - - context 'using cloud config' do - let(:cloud_config_properties) do - { 'azs' => [{ 'name' => 'z1', 'cpi' => 'my-cpi' }] } - end - - before do - db[:deployments].where(id: 42).update(cloud_config_id: 37) - end - - it 'sets the cpi' do - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('my-cpi') - end - - context 'az does not configure cpi' do - let(:cloud_config_properties) do - { 'azs' => [{ 'name' => 'z1' }] } - end - - it 'does not assign cpi to disk' do - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('') - end - end - - context 'if cloud config has 3 AZs, in an instance without an AZ' do - let(:cloud_config_properties) do - { - 'azs' => [ - { 'name' => 'z4', 'cpi' => 'my-cpi-1' }, - { 'name' => 'z2', 'cpi' => 'my-cpi-2' }, - { 'name' => 'z3', 'cpi' => 'my-cpi-3' }, - ], - } - end - - it 'does not assign cpi to disk' do - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('') - end - end - - context 'if no AZs defined' do - let(:cloud_config_properties) do - {} - end - - it 'does not assign cpi to disk' do - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('') - end - end - - context 'if the cloud config is badly formed' do - it 'does not assign cpi to disk' do - db[:cloud_configs].where(id: 37).update(properties: 'true: true: true') - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('') - end - end - end - - context 'without cloud config' do - it 'if the deployment does not use cloud config' do - DBSpecHelper.migrate(migration_file) - subject = db[:persistent_disks].all[0] - expect(subject[:cpi]).to eq('') - end - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170705211620_add_templates_json_to_templates_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170705211620_add_templates_json_to_templates_spec.rb deleted file mode 100644 index 4c0a3aa5c5f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170705211620_add_templates_json_to_templates_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add_templates_json_to_templates' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170705211620_add_templates_json_to_templates.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'adds a templates_json column that allows long text' do - DBSpecHelper.migrate(migration_file) - db[:releases] << {id: 1, name: 'test_release'} - - large_json = "{\"key\": \"#{"foo" * 1000}\"}" - template = { - name: 'template_name_2', - release_id: 1, - version: 'abcd12345', - blobstore_id: '1', - package_names_json: '{}', - sha1: "sha1", - provides_json: '{}', - consumes_json: '{}', - templates_json: large_json, - } - db[:templates] << template - - refreshed = db[:templates].first - template.keys.each do |key| - expect(refreshed[key]).to eq(template[key]) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170803163303_register_known_az_names_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170803163303_register_known_az_names_spec.rb deleted file mode 100644 index 951af14b2a7..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170803163303_register_known_az_names_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'register_known_az_names' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170803163303_register_known_az_names.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { - name: 'deployment-1', - id: 1, - } - db[:variable_sets] << { - id: 15, - deployment_id: 1, - created_at: Time.now, - } - end - - def add_instance_to_az(az_name) - db[:instances] << { - availability_zone: az_name, - index: 0, - job: 'some-instance-group', - deployment_id: 1, - state: 'detached', - variable_set_id: 15, - } - - db[:local_dns_records] << { - ip: 'somewhere', - instance_id: db[:instances].max(:id), - } - end - - it 'inserts a record for every az name in dns records table and a dns tombstone' do - add_instance_to_az('z1') - add_instance_to_az('z2') - add_instance_to_az('z2') - - expect { - DBSpecHelper.migrate(migration_file) - }.to change { - db[:local_dns_records].max(:id) - }.from(3).to(4) - - azs = db[:local_dns_encoded_azs].select(:name).all - expect(azs).to contain_exactly( - {name: 'z1'}, - {name: 'z2'}, - ) - end - - it 'does not attempt to register a null az' do - add_instance_to_az('z1') - add_instance_to_az(nil) - add_instance_to_az(nil) - - DBSpecHelper.migrate(migration_file) - - azs = db[:local_dns_encoded_azs].select(:name).all - expect(azs).to contain_exactly( - {name: 'z1'}, - ) - end - - it 'does not insert tombstone if the local dns records table is empty' do - expect(db[:local_dns_records].all.count).to eq 0 - - expect { - DBSpecHelper.migrate(migration_file) - }.not_to change { - db[:local_dns_records].all.count - } - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs_spec.rb deleted file mode 100644 index 4f5e5cfc52e..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170804191205_add_deployment_and_errand_name_to_errand_runs_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add_deployment_and_errand_name_to_errand_runs' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170804191205_add_deployment_and_errand_name_to_errand_runs.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - before do - db[:deployments] << { name: 'fake-deployment', id: 42 } - db[:variable_sets] << { id: 57, deployment_id: 42, created_at: Time.now } - db[:instances] << { id: 123, availability_zone: 'z1', deployment_id: 42, job: 'instance_job', index: 23, state: 'started', variable_set_id: 57 } - db[:errand_runs] << { id: 1, instance_id: 123 } - end - - it 'deletes existing records' do - DBSpecHelper.migrate(migration_file) - - expect(db[:errand_runs].count).to eq(0) - end - - it 'removes the instance_id column and adds deployment foreign key, errand name and leaves the configuration column' do - DBSpecHelper.migrate(migration_file) - - expect(db[:errand_runs].columns).to contain_exactly(:id, :successful_state_hash, :deployment_id, :errand_name) - end - - it 'sets cascading deletion for deployment foreign key' do - DBSpecHelper.migrate(migration_file) - - db[:errand_runs] << {id: 1, deployment_id: 42} - - db[:instances].delete - db[:deployments].delete - expect(db[:errand_runs].count).to eq(0) - end - - it 'does not cause deletion of an errand run to delete associated deployment' do - DBSpecHelper.migrate(migration_file) - - db[:errand_runs] << {id: 1, deployment_id: 42} - - db[:errand_runs].delete - expect(db[:deployments].count).to eq(1) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170815175515_change_variable_ids_to_bigint_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170815175515_change_variable_ids_to_bigint_spec.rb deleted file mode 100644 index 879f758b0fe..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170815175515_change_variable_ids_to_bigint_spec.rb +++ /dev/null @@ -1,120 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'change id from int to bigint variable_sets & variables', truncation: true do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170815175515_change_variable_ids_to_bigint.rb' } - let(:some_time) do - Time.at(Time.now.to_i).utc - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {id: 1, name: 'deployment_1'} - db[:deployments] << {id: 2, name: 'deployment_5'} - - end - - def can_insert_value_with_bigint(table, record, where_clause) - db[table] << record - expect(db[table].where(where_clause)).to_not be_empty - end - - describe 'variable_sets' do - it 'does NOT impact existing data' do - db[:variable_sets] << {deployment_id: 1, created_at: some_time} - - DBSpecHelper.migrate(migration_file) - - expect(db[:variable_sets].first).to include({:id=>1, :deployment_id=>1, :created_at=>some_time}) - end - - it 'continues auto incrementing ids from original series' do - db[:variable_sets] << {deployment_id: 1, created_at: some_time} - former_max_id = db[:variable_sets].all[-1][:id] - - DBSpecHelper.migrate(migration_file) - - db[:variable_sets] << {deployment_id: 2, created_at: some_time} - new_max_id = db[:variable_sets].all[-1][:id] - expect(new_max_id > former_max_id).to be_truthy - end - - it 'variable_sets id should change the type from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:variable_sets] << {id: 8589934592, deployment_id: 1, created_at: some_time} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:variable_sets].first[:id] == 8589934592 - }.to raise_error(Sequel::DatabaseError) - - DBSpecHelper.migrate(migration_file) - - can_insert_value_with_bigint(:variable_sets, {id: 9223372036854775807, deployment_id: 2, created_at: some_time}, Sequel.lit('id = 9223372036854775807')) - end - - end - - describe 'variables' do - before do - db[:variable_sets] << {id:1, deployment_id: 1, created_at: some_time} - db[:variable_sets] << {id:2, deployment_id: 2, created_at: some_time} - end - - it 'does NOT impact existing data' do - db[:variables] << {variable_set_id: 1, variable_id: 'some_id', variable_name: 'some_name'} - - DBSpecHelper.migrate(migration_file) - - expect(db[:variables].first).to include({:id=>1, variable_set_id: 1, variable_id: 'some_id', variable_name: 'some_name'}) - end - - it 'continues auto incrementing ids from original series' do - db[:variables] << {variable_set_id: 1, variable_id: 'some_id', variable_name: 'some_name'} - former_max_id = db[:variables].all[-1][:id] - - DBSpecHelper.migrate(migration_file) - - db[:variables] << {variable_set_id: 2, variable_id: 'some_id_2', variable_name: 'some_name_2'} - new_max_id = db[:variables].all[-1][:id] - expect(new_max_id > former_max_id).to be_truthy - end - - it 'variables id should change the type from int to bigint' do - DBSpecHelper.skip_on_sqlite(self, 'int == bigint') - - expect { - db[:variables] << {id: 8589934592, variable_set_id: 1, variable_id: 'some_id', variable_name: 'some_name'} - - # MariaDB does not error when inserting record, and instead just truncates records - raise unless db[:variables].first[:id] == 8589934592 - }.to raise_error(Sequel::DatabaseError) - - DBSpecHelper.migrate(migration_file) - - can_insert_value_with_bigint(:variables, {id: 9223372036854775807, variable_set_id: 2, variable_id: 'some_id_2', variable_name: 'some_name_2'}, Sequel.lit('id = 9223372036854775807')) - end - - it 'cascades on variable_sets deletion' do - DBSpecHelper.migrate(migration_file) - db[:variables] << {id: 1, variable_id: 'var_id_1', variable_name: 'var_1', variable_set_id: 1} - db[:variables] << {id: 2, variable_id: 'var_id_2', variable_name: 'var_2', variable_set_id: 1} - db[:variables] << {id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 2} - - expect(db[:variables].count).to eq(3) - - db[:variable_sets].where(id: 1).delete - - expect(db[:variables].count).to eq(1) - expect(db[:variables].first).to include({id: 3, variable_id: 'var_id_3', variable_name: 'var_3', variable_set_id: 2}) - end - - end - - end -end - - diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170821141953_remove_unused_credentials_json_columns_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170821141953_remove_unused_credentials_json_columns_spec.rb deleted file mode 100644 index 887cd504741..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170821141953_remove_unused_credentials_json_columns_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'remove_unused_credentials_json_columns' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170821141953_remove_unused_credentials_json_columns.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - before do - db[:deployments] << { name: 'fake-deployment', id: 1 } - db[:variable_sets] << { id: 2, deployment_id: 1, created_at: Time.now } - db[:instances] << { id: 3, availability_zone: 'z1', deployment_id: 1, job: 'instance_job', index: 0, state: 'started', variable_set_id: 2 } - end - - it 'drops credentials_json_bak column from instances table' do - expect(db[:instances].columns).to include(:credentials_json_bak) - - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].columns).to_not include(:credentials_json_bak) - end - - it 'drops credentials_json column from instances table' do - expect(db[:vms].columns).to include(:credentials_json) - - DBSpecHelper.migrate(migration_file) - - expect(db[:vms].columns).to_not include(:credentials_json) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6_spec.rb deleted file mode 100644 index f6561b31090..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170825141953_change_address_to_be_string_for_ipv6_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'change address column in IP address to be a string to record IPv6 addresses' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170825141953_change_address_to_be_string_for_ipv6.rb' } - - before { DBSpecHelper.migrate_all_before(migration_file) } - - it 'allows instance_id to be null' do - db[:ip_addresses] << {id: 1, instance_id: nil, address: IPAddr.new("192.168.50.6", Socket::AF_INET).to_i} - - DBSpecHelper.migrate(migration_file) - - expect(db[:ip_addresses].first[:address_str]).to eq(IPAddr.new("192.168.50.6", Socket::AF_INET).to_i.to_s) - - expect { - db[:ip_addresses] << {id: 2, instance_id: nil, address_str: IPAddr.new("192.168.50.6", Socket::AF_INET).to_i.to_s} - }.to raise_error(Sequel::UniqueConstraintViolation, /ip_addresses.address/) - - expect { - db[:ip_addresses] << {id: 3, instance_id: nil, address_str: nil} - }.to raise_error(Sequel::NotNullConstraintViolation, /address_str/) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170828174622_add_spec_json_to_templates_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170828174622_add_spec_json_to_templates_spec.rb deleted file mode 100644 index ba17a0e1129..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170828174622_add_spec_json_to_templates_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add_spec_json_to_templates' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170828174622_add_spec_json_to_templates.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - before do - db[:releases] << { - name: 'hello' - } - end - - it 'allows you to save a spec-json' do - DBSpecHelper.migrate(migration_file) - expect(db[:templates].columns).to include(:spec_json) - - db[:templates] << { - name: 'some-job', - spec_json: '{"anything": "json"}', - version: '23', - blobstore_id: 'abc123', - release_id: 1, - package_names_json: '{}', - sha1: 'shasha', - } - - expect(db[:templates].first[:spec_json]).to eq '{"anything": "json"}' - end - - it 'ensures that spec_json allows texts longer than 65535 character' do - DBSpecHelper.migrate(migration_file) - - really_long_spec_json = 'a' * 65536 - db[:templates] << { - name: 'some-job', - spec_json: really_long_spec_json, - version: '23', - blobstore_id: 'abc123', - release_id: 1, - package_names_json: '{}', - sha1: 'shasha', - } - - expect(db[:templates].first[:spec_json].length).to eq(really_long_spec_json.length) - end - - it 'backfills values from logs, templates, provides, consumes, and properties' do - db[:templates] << { - name: 'some-job', - version: '23', - blobstore_id: 'abc123', - release_id: 1, - package_names_json: '{"old":"packages"}', - properties_json: '{"old":"properties"}', - provides_json: '{"old":"provides"}', - consumes_json: '{"old":"consumes"}', - logs_json: '{"old":"logs"}', - sha1: 'shasha', - } - - DBSpecHelper.migrate(migration_file) - - expect(JSON.load(db[:templates].first[:spec_json])).to eq({ - 'properties' => {'old' => 'properties'}, - 'provides' => {'old' => 'provides'}, - 'consumes' => {'old' => 'consumes'}, - 'logs' => {'old' => 'logs'}, - }) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups_spec.rb deleted file mode 100644 index 631861cc952..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20170915205722_create_dns_encoded_networks_and_instance_groups_spec.rb +++ /dev/null @@ -1,210 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'create_dns_groups' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20170915205722_create_dns_encoded_networks_and_instance_groups.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { - id: 42, - name: 'fake_deployment' - } - - db[:deployments] << { - id: 28, - name: 'fake_deployment_2' - } - end - - it 'creates tables for instance group names and networks' do - DBSpecHelper.migrate(migration_file) - - db[:local_dns_encoded_instance_groups] << { - name: 'test_ig', - deployment_id: 42 - } - - expect(db[:local_dns_encoded_instance_groups].first).to eq({ - id: 1, - name: 'test_ig', - deployment_id: 42 - }) - - db[:local_dns_encoded_networks] << { - id: 7, - name: 'test_network' - } - - expect(db[:local_dns_encoded_networks].first).to eq({ - id: 7, - name: 'test_network' - }) - end - - describe 'instance group encodings' do - let(:basic_ig) do - { name: 'test_ig', deployment_id: 42 } - end - let(:ig_in_other_deployment) do - { name: 'test_ig', deployment_id: 28 } - end - let(:ig_with_other_name) do - { name: 'test_ig_2', deployment_id: 42 } - end - - before do - DBSpecHelper.migrate(migration_file) - end - - it 'does not allow dupes of an instance group name within a deployment' do - db[:local_dns_encoded_instance_groups] << basic_ig - db[:local_dns_encoded_instance_groups] << ig_in_other_deployment - db[:local_dns_encoded_instance_groups] << ig_with_other_name - - expect { - db[:local_dns_encoded_instance_groups] << basic_ig - }.to raise_error Sequel::UniqueConstraintViolation - end - - it 'enforces valid instance groups' do - expect { - db[:local_dns_encoded_instance_groups] << { - name: 'test_ig', - deployment_id: 39 - } - }.to raise_error Sequel::ForeignKeyConstraintViolation - - expect { - db[:local_dns_encoded_instance_groups] << { - name: 'test_ig', - deployment_id: nil - } - }.to raise_error Sequel::NotNullConstraintViolation - expect { - db[:local_dns_encoded_instance_groups] << { - name: nil, - deployment_id: 42 - } - }.to raise_error Sequel::NotNullConstraintViolation - end - - it 'does not prevent deployment deletion' do - db[:local_dns_encoded_instance_groups] << basic_ig - expect(db[:local_dns_encoded_instance_groups].where(name: 'test_ig').all.count).to eq 1 - db[:deployments].where(id: 42).delete - expect(db[:local_dns_encoded_instance_groups].where(name: 'test_ig').all.count).to eq 0 - end - end - - describe 'encoded networks' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'does not allow dupes' do - db[:local_dns_encoded_networks] << { - id: 1, - name: 'net1' - } - - expect { - db[:local_dns_encoded_networks] << { - id: 2, - name: 'net1' - } - }.to raise_error Sequel::UniqueConstraintViolation - - expect { - db[:local_dns_encoded_networks] << { - id: 1, - name: 'net3' - } - }.to raise_error Sequel::UniqueConstraintViolation - - db[:local_dns_encoded_networks] << { - id: 2, - name: 'net2' - } - end - - it 'requires a real network name' do - expect { - db[:local_dns_encoded_networks] << { - id: 1, - name: nil - } - }.to raise_error Sequel::NotNullConstraintViolation - end - end - - describe 'backfilling known content' do - it 'records known network names from existing local_dns_records table' do - db[:local_dns_records] << { - ip: 'dumdumdum', - network: 'some-network' - } - db[:local_dns_records] << { - ip: 'dumdumdum', - network: 'another' - } - db[:local_dns_records] << { - ip: 'new-ip', - network: 'another' - } - db[:local_dns_records] << { - ip: 'new-ip', - network: nil - } - DBSpecHelper.migrate(migration_file) - expect(db[:local_dns_encoded_networks].all.count).to eq 2 - expect(db[:local_dns_encoded_networks].all).to include(id: anything, name: 'some-network') - expect(db[:local_dns_encoded_networks].all).to include(id: anything, name: 'another') - end - - it 'records known encoded instance groups from existing local_dns_records table' do - db[:variable_sets] << { - id: 15, - deployment_id: 28, - created_at: Time.now, - } - - db[:instances] << { - job: 'alice', - index: 0, - deployment_id: 28, - state: 'running', - variable_set_id: 15 - } - db[:instances] << { - job: 'bob', - index: 1, - deployment_id: 28, - state: 'running', - variable_set_id: 15 - } - db[:instances] << { - job: 'bob', - index: 2, - deployment_id: 28, - state: 'running', - variable_set_id: 15 - } - db[:instances] << { - job: 'alice', - index: 0, - deployment_id: 42, - state: 'running', - variable_set_id: 15 - } - DBSpecHelper.migrate(migration_file) - expect(db[:local_dns_encoded_instance_groups].all.count).to eq 3 - expect(db[:local_dns_encoded_instance_groups].all).to include(id: anything, name: 'alice', deployment_id: 28) - expect(db[:local_dns_encoded_instance_groups].all).to include(id: anything, name: 'bob', deployment_id: 28) - expect(db[:local_dns_encoded_instance_groups].all).to include(id: anything, name: 'alice', deployment_id: 42) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171010150659_migrate_runtime_configs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171010150659_migrate_runtime_configs_spec.rb deleted file mode 100644 index b1360d66cf8..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171010150659_migrate_runtime_configs_spec.rb +++ /dev/null @@ -1,94 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'runtime configs migration' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171010150659_migrate_runtime_configs.rb'} - let(:some_time) do - Time.at(Time.now.to_i).utc - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it "creates table 'deployments_configs' and derives content from 'deployments_runtime_configs'" do - db[:deployments] << { name: 'fake-name'} - db[:runtime_configs] << { properties: 'old content with name', name: 'old_name', created_at: some_time } - db[:deployments_runtime_configs] << { deployment_id: 1, runtime_config_id: 1 } - - DBSpecHelper.migrate(migration_file) - - deployment_runtime = db[:deployments_configs].first - expect(deployment_runtime).to be - expect(deployment_runtime[:deployment_id]).to be 1 - expect(deployment_runtime[:config_id]).to be 1 - end - - context 'without name' do - it "copies 'runtime_configs' data into 'configs' table and updates 'deployments_configs' table" do - db[:deployments] << { id: 2, name: 'fake-name'} - db[:runtime_configs] << { id: 3, properties: 'old content', created_at: some_time } - db[:deployments_runtime_configs] << { deployment_id: 2, runtime_config_id: 3 } - - DBSpecHelper.migrate(migration_file) - - expect(db[:configs].count).to eq(1) - deployment_runtime = db[:deployments_configs].first - expect(deployment_runtime[:config_id]).to be - new_config = db[:configs].where(id: deployment_runtime[:config_id]).first - expect(new_config).to include({ - type: 'runtime', - name: 'default', - content: 'old content', - created_at: some_time - }) - end - end - - context 'with name' do - it 'copies config data into config table and updates deployments runtime configs table' do - db[:deployments] << { name: 'fake-name'} - db[:runtime_configs] << { properties: 'old content with name', name: 'old_name', created_at: some_time } - db[:deployments_runtime_configs] << { deployment_id: 1, runtime_config_id: 1 } - - DBSpecHelper.migrate(migration_file) - - deployment_runtime_with_name = db[:deployments_configs].first - expect(deployment_runtime_with_name[:config_id]).to be - new_config_with_name = db[:configs].where(id: deployment_runtime_with_name[:config_id]).first - expect(new_config_with_name).to include({ - type: 'runtime', - name: 'old_name', - content: 'old content with name', - created_at: some_time - }) - end - - it "'default' gets renamed to 'default-'" do - allow(SecureRandom).to receive(:uuid).and_return('fakeUUID') - db[:deployments] << { name: 'fake-name'} - db[:runtime_configs] << { properties: 'old content with name', name: 'default', created_at: some_time } - db[:deployments_runtime_configs] << { deployment_id: 1, runtime_config_id: 1 } - - DBSpecHelper.migrate(migration_file) - - deployment_runtime_with_name = db[:deployments_configs].first - expect(deployment_runtime_with_name[:config_id]).to be - new_config_with_name = db[:configs].where(id: deployment_runtime_with_name[:config_id]).first - expect(new_config_with_name).to include({ - type: 'runtime', - name: 'default-fakeUUID', - content: 'old content with name', - created_at: some_time - }) - end - end - - it "drops 'deployments_runtime_config' table" do - expect(db.tables).to include(:deployments_runtime_configs) - DBSpecHelper.migrate(migration_file) - expect(db.tables).to_not include(:deployments_runtime_configs) - end - end -end \ No newline at end of file diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171010161532_migrate_cloud_configs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171010161532_migrate_cloud_configs_spec.rb deleted file mode 100644 index 3e24e04c9c9..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171010161532_migrate_cloud_configs_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'cloud configs migrations' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171010161532_migrate_cloud_configs.rb'} - let(:some_time) do - Time.at(Time.now.to_i).utc - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it "copies 'cloud_configs' data into 'configs' table and updates 'deployments_configs' table" do - db[:cloud_configs] << { id: 3, properties: 'old content', created_at: some_time } - db[:deployments] << { id: 2, name: 'fake-name', cloud_config_id: 3} - - DBSpecHelper.migrate(migration_file) - - expect(db[:configs].count).to eq(1) - deployment_config = db[:deployments_configs].first - expect(deployment_config[:config_id]).to be - new_config = db[:configs].where(id: deployment_config[:config_id]).first - expect(new_config).to include({ - type: 'cloud', - name: 'default', - content: 'old content', - created_at: some_time - }) - end - - it "drops the foreign key `cloud_config_id` from `deployments`" do - expect(db[:deployments].columns.include?(:cloud_config_id)).to be_truthy - - DBSpecHelper.migrate(migration_file) - - expect(db[:deployments].columns.include?(:cloud_config_id)).to be_falsey - end - end -end \ No newline at end of file diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171011122118_migrate_cpi_configs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171011122118_migrate_cpi_configs_spec.rb deleted file mode 100644 index 03096b50c1f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171011122118_migrate_cpi_configs_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'cpi configs migrations' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171011122118_migrate_cpi_configs.rb'} - let(:some_time) do - Time.at(Time.now.to_i).utc - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it "copies 'cpi_configs' data into 'configs' table" do - db[:cpi_configs] << { id: 3, properties: 'old content', created_at: some_time } - - DBSpecHelper.migrate(migration_file) - - expect(db[:configs].count).to eq(1) - - new_config = db[:configs].first - expect(new_config).to include({ - type: 'cpi', - name: 'default', - content: 'old content', - created_at: some_time - }) - end - end -end \ No newline at end of file diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171018102040_remove_compilation_local_dns_records_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171018102040_remove_compilation_local_dns_records_spec.rb deleted file mode 100644 index b4b4ac90dfb..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171018102040_remove_compilation_local_dns_records_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20171018102040_remove_compilation_local_dns_records' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20171018102040_remove_compilation_local_dns_records.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {deployment_id: 1, created_at: Time.now} - - db[:instances] << { - job: "fake-ig", - uuid: "fake-uuid1", - index: 1, - deployment_id: 1, - compilation: compilation, - state: "started", - availability_zone: "fake-az1", - variable_set_id: 1, - spec_json: "{}", - } - db[:local_dns_records] << { - instance_id: 1, - instance_group: "fake-ig", - az: "fake-az", - network: "fake-network", - deployment: "fake-deployment", - ip: "192.0.2.1", - } - end - - context 'compilation instances' do - let(:compilation) { true } - - it 'removes local dns records which referenced compilation instances' do - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].all.size).to eq(0) - end - end - - context 'non-compilation instances' do - let(:compilation) { false } - - it 'retains local dns records' do - DBSpecHelper.migrate(migration_file) - - expect(db[:local_dns_records].all.size).to eq(1) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171030224934_convert_nil_configs_to_empty_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171030224934_convert_nil_configs_to_empty_spec.rb deleted file mode 100644 index e6deb1c11f2..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171030224934_convert_nil_configs_to_empty_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'db_spec_helper' - -module Bosh::Director - describe '20171030224934_convert_nil_configs_to_empty' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20171030224934_convert_nil_configs_to_empty.rb' } - let(:created_at) { Time.now } - let(:content) { nil } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:configs] << { - type: 'anything', - name: 'anything', - content: content, - created_at: created_at, - } - - DBSpecHelper.migrate(migration_file) - end - - context 'content is empty' do - it 'converts to empty hash' do - expect(db[:configs].all.first[:content]).to eq '--- {}' - end - end - - context 'content is YAML-nil' do - let(:content) { "--- \n... \n" } - - it 'converts to empty hash' do - expect(db[:configs].all.first[:content]).to eq '--- {}' - end - end - - context 'content is bad YAML syntax' do - let(:content) { '{bad=yml' } - - it 'leaves it alone and continues' do - expect(db[:configs].all.first[:content]).to eq '{bad=yml' - end - end - - it 'does not allow new configs with nil content' do - expect { - db[:configs] << { - type: 'anything', - name: 'anything', - content: content, - created_at: created_at, - } - }.to raise_error(Sequel::NotNullConstraintViolation) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171104185823_add_manifest_text_to_deployments_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171104185823_add_manifest_text_to_deployments_spec.rb deleted file mode 100644 index 562f1898e5a..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171104185823_add_manifest_text_to_deployments_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add_manifest_text_to_deployments' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20171104185823_add_manifest_text_to_deployments.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - it 'adds a manifest_text column that allows long text' do - DBSpecHelper.migrate(migration_file) - - long_text = 'a' * 65536 - - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: '{}', manifest_text: long_text} - - deployment = db[:deployments].first - expect(deployment[:manifest_text]).to eq(long_text) - end - - context 'when manifest_text is nil or empty' do - it 'puts manifest as manifest_text' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: YAML.dump({name: 'test'})} - DBSpecHelper.migrate(migration_file) - - deployment = db[:deployments].first - expect(deployment[:manifest_text]).to eq("---\n:name: test\n") - end - - context 'when manifest is nil' do - it 'puts default value' do - db[:deployments] << {id: 1, name: 'fake-deployment-name', manifest: nil} - DBSpecHelper.migrate(migration_file) - - deployment = db[:deployments].first - expect(deployment[:manifest_text]).to eq("{}") - end - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171113000000_add_links_api_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171113000000_add_links_api_spec.rb deleted file mode 100644 index b71a5b22f15..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171113000000_add_links_api_spec.rb +++ /dev/null @@ -1,942 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'During migrations' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171113000000_add_links_api.rb'} - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - context 'verify table columns' do - it 'creates the appropriate tables' do - DBSpecHelper.migrate(migration_file) - expect(db.table_exists? :link_providers).to be_truthy - expect(db.table_exists? :link_provider_intents).to be_truthy - expect(db.table_exists? :link_consumers).to be_truthy - expect(db.table_exists? :link_consumer_intents).to be_truthy - expect(db.table_exists? :links).to be_truthy - expect(db.table_exists? :instances_links).to be_truthy - end - - it 'adds the link_serial_id to deployment' do - db[:deployments] << {name: 'fake-deployment', id: 42} - DBSpecHelper.migrate(migration_file) - - expect(db[:deployments].first[:links_serial_id]).to eq(0) - end - - it 'adds the has_stale_errand_links column to deployment and migrates it to TRUE' do - db[:deployments] << {name: 'fake-deployment', id: 43} - DBSpecHelper.migrate(migration_file) - - expect(db[:deployments].first[:has_stale_errand_links]).to be_truthy - end - - it 'adds the has_stale_errand_links column to deployment and defaults to FALSE' do - DBSpecHelper.migrate(migration_file) - db[:deployments] << {name: 'fake-deployment', id: 43} - - expect(db[:deployments].first[:has_stale_errand_links]).to be_falsey - end - end - - context 'providers migration' do - context 'when link_spec_json is populated in the deployments table' do - let(:link_spec_json) do - { - 'provider_instance_group_1': { - 'provider_job_1': { - 'link_name_1': { - 'link_type_1': {'my_val': 'hello'} - }, - 'link_name_2': { - 'link_type_2': {'foo': 'bar'} - } - } - }, - 'provider_instance_group_2': { - 'provider_job_1': { - 'link_name_3': { - 'link_type_1': {'bar': 'baz'} - }, - }, - 'provider_job_2': { - 'link_name_4': { - 'link_type_2': {'foobar': 'bazbaz'} - } - } - } - } - end - - before do - db[:deployments] << {name: 'fake-deployment', id: 42, link_spec_json: link_spec_json.to_json} - DBSpecHelper.migrate(migration_file) - end - - it 'will create correct links providers' do - expect(db[:link_providers].count).to eq(3) - - expected_links_providers = [ - {instance_group: 'provider_instance_group_1', deployment_id: 42, type: 'job', name: 'provider_job_1', serial_id: 0}, - {instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'job', name: 'provider_job_1', serial_id: 0}, - {instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'job', name: 'provider_job_2', serial_id: 0}, - ] - - db[:link_providers].order(:id).each_with_index do |provider, index| - output = expected_links_providers[index] - expect(provider[:name]).to eq(output[:name]) - expect(provider[:deployment_id]).to eq(output[:deployment_id]) - expect(provider[:instance_group]).to eq(output[:instance_group]) - expect(provider[:type]).to eq(output[:type]) - expect(provider[:serial_id]).to eq(output[:serial_id]) - end - end - - it 'will create correct links providers intents' do - provider_1_id = db[:link_providers].where(instance_group: 'provider_instance_group_1', deployment_id: 42, type: 'job', name: 'provider_job_1', serial_id: 0).first[:id] - provider_2_id = db[:link_providers].where(instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'job', name: 'provider_job_1', serial_id: 0).first[:id] - provider_3_id = db[:link_providers].where(instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'job', name: 'provider_job_2', serial_id: 0).first[:id] - - expected_link_providers_intents = [ - {link_provider_id: provider_1_id, original_name: 'link_name_1', type: 'link_type_1', name: 'link_name_1', content: '{"my_val":"hello"}', serial_id: 0}, - {link_provider_id: provider_1_id, original_name: 'link_name_2', type: 'link_type_2', name: 'link_name_2', content: '{"foo":"bar"}', serial_id: 0}, - {link_provider_id: provider_2_id, original_name: 'link_name_3', type: 'link_type_1', name: 'link_name_3', content: '{"bar":"baz"}', serial_id: 0}, - {link_provider_id: provider_3_id, original_name: 'link_name_4', type: 'link_type_2', name: 'link_name_4', content: '{"foobar":"bazbaz"}', serial_id: 0}, - ] - - expect(db[:link_provider_intents].count).to eq(4) - db[:link_provider_intents].order(:id).each_with_index do |provider_intent, index| - output = expected_link_providers_intents[index] - expect(provider_intent[:link_provider_id]).to eq(output[:link_provider_id]) - expect(provider_intent[:original_name]).to eq(output[:original_name]) - expect(provider_intent[:type]).to eq(output[:type]) - expect(provider_intent[:name]).to eq(output[:name]) - expect(provider_intent[:shared]).to eq(true) - expect(provider_intent[:consumable]).to eq(true) - expect(provider_intent[:serial_id]).to eq(output[:serial_id]) - end - end - end - end - - context 'consumer migration' do - context 'when spec_json is populated with consumed links in the instances table' do - let(:instance_spec_json) do - { - "deployment": "fake-deployment", - "name": "provider_instance_group_1", - "job": { - "name": "provider_instance_group_1", - "templates": [ - { - "name": "http_proxy_with_requires", - "version": "760680c4a796a2ffca24026c561c06dd5bdef6b3", - "sha1": "fdf0d8acd01055f32fb28caee3b5a2d383848e53", - "blobstore_id": "e6a084ab-541c-4f9e-8132-573627bded5a", - "logs": [] - } - ] - }, - "links": { - "http_proxy_with_requires": { - "proxied_http_endpoint": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 15672, - "name_space": { - "fibonacci": "((fibonacci_placeholder))", - "prop_a": "default" - } - } - }, - "proxied_http_endpoint2": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "a": 1, - "name_space": { - "asdf": "((fibonacci_placeholder))", - "dbxcv": "default" - } - } - } - } - } - } - end - let(:expected_owner_object_info) do - { instance_group_name: 'provider_instance_group_1' } - end - - before do - db[:deployments] << {name: 'fake-deployment', id: 42, link_spec_json: "{}"} - db[:variable_sets] << {id: 1, deployment_id: 42, created_at: Time.now} - db[:instances] << { - job: 'provider_instance_group_1', - id: 22, - index: 0, - deployment_id: 42, - state: "started", - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - end - - it 'will create one consumer per consuming job' do - DBSpecHelper.migrate(migration_file) - expect(db[:link_consumers].count).to eq(1) - - expect(db[:link_consumers].first[:deployment_id]).to eq(42) - expect(db[:link_consumers].first[:instance_group]).to eq('provider_instance_group_1') - expect(db[:link_consumers].first[:name]).to eq('http_proxy_with_requires') - expect(db[:link_consumers].first[:type]).to eq('job') - expect(db[:link_consumers].first[:serial_id]).to eq(0) - end - - it 'will create the correct link_consumers_intents' do - DBSpecHelper.migrate(migration_file) - consumer_id = db[:link_consumers].first[:id] - - expected_links_consumers_intents = [ - {:id=>Integer, :link_consumer_id=>consumer_id, :original_name=>'proxied_http_endpoint', :type=>'undefined-migration', :name => 'proxied_http_endpoint', :optional=>false, :blocked=>false, :metadata=> nil, serial_id: 0}, - {:id=>Integer, :link_consumer_id=>consumer_id, :original_name=>'proxied_http_endpoint2', :type=>'undefined-migration', :name => 'proxied_http_endpoint2', :optional=>false, :blocked=>false, :metadata=> nil, serial_id: 0} - ] - - expect(db[:link_consumer_intents].all).to match_array(expected_links_consumers_intents) - end - - context 'multiple instances consume same link' do - before do - db[:instances] << { - job: 'provider_instance_group_1', - id: 23, - index: 0, - deployment_id: 42, - state: "started", - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - end - - it 'will not create duplicate consumers' do - expect(db[:instances].count).to eq(2) - DBSpecHelper.migrate(migration_file) - expect(db[:link_consumers].count).to eq(1) - - expect(db[:link_consumers].first[:deployment_id]).to eq(42) - expect(db[:link_consumers].first[:instance_group]).to eq('provider_instance_group_1') - expect(db[:link_consumers].first[:name]).to eq('http_proxy_with_requires') - expect(db[:link_consumers].first[:type]).to eq('job') - expect(db[:link_consumers].first[:serial_id]).to eq(0) - end - - it 'will create the correct link_consumers_intents' do - DBSpecHelper.migrate(migration_file) - consumer_id = db[:link_consumers].first[:id] - - expected_links_consumers_intents = [ - {:id=>Integer, :link_consumer_id=>consumer_id, :original_name=>'proxied_http_endpoint', :type=>'undefined-migration', :name => 'proxied_http_endpoint', :optional=>false, :blocked=>false, :metadata=>nil, serial_id: 0}, - {:id=>Integer, :link_consumer_id=>consumer_id, :original_name=>'proxied_http_endpoint2', :type=>'undefined-migration', :name => 'proxied_http_endpoint2', :optional=>false, :blocked=>false, :metadata=>nil, serial_id: 0} - ] - - expect(db[:link_consumer_intents].all).to match_array(expected_links_consumers_intents) - end - end - end - end - - context 'link migration' do - context 'when spec_json is populated with consumed links in the instances table' do - let(:instance_spec_json) do - { - "deployment": "fake-deployment", - "name": "provider_instance_group_1", - "job": { - "name": "provider_instance_group_1", - "templates": [ - { - "name": "http_proxy_with_requires", - "version": "760680c4a796a2ffca24026c561c06dd5bdef6b3", - "sha1": "fdf0d8acd01055f32fb28caee3b5a2d383848e53", - "blobstore_id": "e6a084ab-541c-4f9e-8132-573627bded5a", - "logs": [] - } - ] - }, - "links": { - "http_proxy_with_requires": { - "proxied_http_endpoint": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 15672, - "name_space": { - "fibonacci": "((fibonacci_placeholder))", - "prop_a": "default" - } - } - }, - "proxied_http_endpoint2": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "a": 1, - "name_space": { - "asdf": "((fibonacci_placeholder))", - "dbxcv": "default" - } - } - } - } - } - } - end - - before do - db[:deployments] << {name: 'fake-deployment', id: 42, link_spec_json: "{}"} - db[:variable_sets] << {id: 1, deployment_id: 42, created_at: Time.now} - db[:instances] << { - job: 'provider_instance_group_1', - id: 22, - index: 0, - deployment_id: 42, - state: "started", - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - end - - it 'will create one link per consuming instance group/job/link name' do - before = Time.now - DBSpecHelper.migrate(migration_file) - after = Time.now - - link_consumer_intent_1 = db[:link_consumer_intents].where(original_name: 'proxied_http_endpoint').first - link_consumer_intent_2 = db[:link_consumer_intents].where(original_name: 'proxied_http_endpoint2').first - - expect(db[:links].count).to eq(2) - - link_1_expected_content = { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 15672, - "name_space": { - "fibonacci": "((fibonacci_placeholder))", - "prop_a": "default" - } - } - }.to_json - - links_1 = db[:links].where(name: 'proxied_http_endpoint').first - expect(links_1[:link_provider_intent_id]).to be_nil - expect(links_1[:link_consumer_intent_id]).to eq(link_consumer_intent_1[:id]) - expect(links_1[:link_content]).to eq(link_1_expected_content) - expect(links_1[:created_at].to_i).to be >= before.to_i - expect(links_1[:created_at].to_i).to be <= after.to_i - - link_2_expected_content = { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "a": 1, - "name_space": { - "asdf": "((fibonacci_placeholder))", - "dbxcv": "default" - } - } - }.to_json - - links_2 = db[:links].where(name: 'proxied_http_endpoint2').first - expect(links_2[:link_provider_intent_id]).to be_nil - expect(links_2[:link_consumer_intent_id]).to eq(link_consumer_intent_2[:id]) - expect(links_2[:link_content]).to eq(link_2_expected_content) - expect(links_2[:created_at].to_i).to be >= before.to_i - expect(links_2[:created_at].to_i).to be <= after.to_i - end - - it 'will create one instance_link per job per consuming instance' do - DBSpecHelper.migrate(migration_file) - expect(db[:instances_links].count).to eq(2) - - dataset = db[:instances_links].all - expect(dataset[0][:instance_id]).to eq(22) - expect(dataset[0][:link_id]).to eq(1) - expect(dataset[0][:serial_id]).to eq(0) - - expect(dataset[1][:instance_id]).to eq(22) - expect(dataset[1][:link_id]).to eq(2) - expect(dataset[1][:serial_id]).to eq(0) - end - - it 'will remove the links key from spec_json' do - DBSpecHelper.migrate(migration_file) - - db[:instances].all.each do |instance| - spec_json = instance[:spec_json] - spec = JSON.load(spec_json) - expect(spec.has_key?('links')).to be_falsey - end - end - - context 'when link_consumer is deleted: #cascade relationship' do - it 'should delete associated link_consumer_intents and links' do - DBSpecHelper.migrate(migration_file) - - link_consumer_1 = db[:link_consumers].where(name: 'http_proxy_with_requires').first - link_consumer_intent_1 = db[:link_consumer_intents].where(original_name: 'proxied_http_endpoint').first - link_1 = db[:links].where(name: 'proxied_http_endpoint').first - - expect{db[:link_consumers].where(id: link_consumer_1[:id]).delete}.to_not raise_error - - expect(db[:link_consumer_intents].where(id: link_consumer_intent_1[:id]).first).to be_nil - expect(db[:links].where(link_consumer_intent_id: link_consumer_intent_1[:id]).count).to eq(0) - end - end - - context 'when deployment is deleted' do - before do - DBSpecHelper.migrate(migration_file) - db[:instances].delete - end - - it 'should delete all links, providers, consumers' do - expect{db[:deployments].where(id: 42).delete}.to_not raise_error - expect(db[:links].count).to eq(0) - expect(db[:link_consumers].count).to eq(0) - expect(db[:link_providers].count).to eq(0) - expect(db[:link_provider_intents].count).to eq(0) - expect(db[:link_consumer_intents].count).to eq(0) - expect(db[:instances_links].count).to eq(0) - end - end - end - - context 'when multiple instances contain the same link key' do - let(:instance_spec_json) do - { - "deployment": "fake-deployment", - "name": "provider_instance_group_1", - "job": { - "name": "provider_instance_group_1", - "templates": [ - { - "name": "http_proxy_with_requires", - "version": "760680c4a796a2ffca24026c561c06dd5bdef6b3", - "sha1": "fdf0d8acd01055f32fb28caee3b5a2d383848e53", - "blobstore_id": "e6a084ab-541c-4f9e-8132-573627bded5a", - "logs": [] - } - ] - }, - "links": { - "http_proxy_with_requires": { - "proxied_http_endpoint": link_content - } - } - } - end - - let(:link_content) do - { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 15672, - "name_space": { - "fibonacci": "((fibonacci_placeholder))", - "prop_a": "default" - } - } - } - end - - before do - db[:deployments] << {name: 'fake-deployment', id: 42, link_spec_json: "{}"} - db[:variable_sets] << {id: 1, deployment_id: 42, created_at: Time.now} - db[:instances] << { - job: 'provider_instance_group_1', - id: 22, - index: 0, - deployment_id: 42, - state: 'started', - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - end - - # having 2 links with same contents should be ok as well, test for it - context 'and contents are the same' do - before do - db[:instances] << { - job: 'provider_instance_group_1', - id: 23, - index: 1, - deployment_id: 42, - state: 'started', - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - end - - it 'should create only one link' do - before = Time.now - DBSpecHelper.migrate(migration_file) - after = Time.now - - link_consumers_1_id = db[:link_consumers].where(name: 'http_proxy_with_requires').first[:id] - link_consumers_intent_1_id = db[:link_consumer_intents].where(original_name: 'proxied_http_endpoint', link_consumer_id: link_consumers_1_id).first[:id] - - expect(link_consumers_intent_1_id).to_not be_nil - expect(db[:links].count).to eq(1) - - expect(db[:links].first[:name]).to eq('proxied_http_endpoint') - expect(db[:links].first[:link_provider_intent_id]).to be_nil - expect(db[:links].first[:link_consumer_intent_id]).to eq(link_consumers_intent_1_id) - expect(db[:links].first[:link_content]).to eq(link_content.to_json) - expect(db[:links].first[:created_at].to_i).to be >= before.to_i - expect(db[:links].first[:created_at].to_i).to be <= after.to_i - end - - it 'will create one instance_link per consuming instance' do - DBSpecHelper.migrate(migration_file) - expect(db[:instances_links].count).to eq(2) - - dataset = db[:instances_links].all - expect(dataset[0][:instance_id]).to eq(22) - expect(dataset[0][:link_id]).to eq(1) - expect(dataset[0][:serial_id]).to eq(0) - - expect(dataset[1][:instance_id]).to eq(23) - expect(dataset[1][:link_id]).to eq(1) - expect(dataset[1][:serial_id]).to eq(0) - end - end - - # multiple links attached to the same consumer intent??? - # how we do the equality of the links contents, need to validate it is correct ??? - # the order of the hash contents and keys should be ok - - context 'and contents are different' do - let(:instance_spec_json2) do - { - "deployment": "fake-deployment", - "name": "provider_instance_group_1", - "job": { - "name": "provider_instance_group_1", - "templates": [ - { - "name": "http_proxy_with_requires", - "version": "760680c4a796a2ffca24026c561c06dd5bdef6b3", - "sha1": "fdf0d8acd01055f32fb28caee3b5a2d383848e53", - "blobstore_id": "e6a084ab-541c-4f9e-8132-573627bded5a", - "logs": [] - } - ] - }, - "links": { - "http_proxy_with_requires": { - "proxied_http_endpoint": link_content2 - } - } - } - end - - let(:link_content2) do - { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 1111, - "name_space": { - "fibonacci": "1 2 3 5 8 13 21 34 55 89 144", - "prop_a": "ALPHABET!" - } - } - } - end - - before do - db[:instances] << { - job: 'provider_instance_group_1', - id: 23, - index: 1, - deployment_id: 42, - state: "started", - variable_set_id: 1, - spec_json: instance_spec_json2.to_json - } - end - - it 'should create two distinct link rows' do - before = Time.now - DBSpecHelper.migrate(migration_file) - after = Time.now - - link_consumers_1_id = db[:link_consumers].where(name: 'http_proxy_with_requires').first[:id] - link_consumers_intent_1_id = db[:link_consumer_intents].where(original_name: 'proxied_http_endpoint', link_consumer_id: link_consumers_1_id).first[:id] - expect(link_consumers_intent_1_id).to_not be_nil - - links_dataset = db[:links] - expect(links_dataset.count).to eq(2) - - link_rows = links_dataset.all - - expect(link_rows[0][:name]).to eq('proxied_http_endpoint') - expect(link_rows[0][:link_provider_intent_id]).to be_nil - expect(link_rows[0][:link_consumer_intent_id]).to eq(link_consumers_intent_1_id) - expect(link_rows[0][:link_content]).to eq(link_content.to_json) - expect(db[:links].first[:created_at].to_i).to be >= before.to_i - expect(db[:links].first[:created_at].to_i).to be <= after.to_i - - expect(link_rows[1][:name]).to eq('proxied_http_endpoint') - expect(link_rows[1][:link_provider_intent_id]).to be_nil - expect(link_rows[1][:link_consumer_intent_id]).to eq(link_consumers_intent_1_id) - expect(link_rows[1][:link_content]).to eq(link_content2.to_json) - expect(db[:links].first[:created_at].to_i).to be >= before.to_i - expect(db[:links].first[:created_at].to_i).to be <= after.to_i - end - - it 'will create one instance_link per consuming instance' do - DBSpecHelper.migrate(migration_file) - expect(db[:instances_links].count).to eq(2) - - dataset = db[:instances_links].all - expect(dataset[0][:instance_id]).to eq(22) - expect(dataset[0][:link_id]).to eq(1) - expect(dataset[0][:serial_id]).to eq(0) - - expect(dataset[1][:instance_id]).to eq(23) - expect(dataset[1][:link_id]).to eq(2) - expect(dataset[1][:serial_id]).to eq(0) - end - end - end - end - - context 'verify all unique constraints' do - let(:link_spec_json) do - { - 'provider_instance_group_1': { - 'provider_job_1': { - 'link_name_1': { - 'link_type_1': {'my_val': 'hello'} - }, - 'link_name_2': { - 'link_type_2': {'foo': 'bar'} - } - } - }, - 'provider_instance_group_2': { - 'provider_job_1': { - 'link_name_3': { - 'link_type_1': {'bar': 'baz'} - }, - }, - 'provider_job_2': { - 'link_name_4': { - 'link_type_2': {'foobar': 'bazbaz'} - } - } - } - } - end - let(:instance_spec_json) do - { - "deployment": "fake-deployment", - "name": "provider_instance_group_1", - "job": { - "name": "provider_instance_group_1", - "templates": [ - { - "name": "http_proxy_with_requires", - "version": "760680c4a796a2ffca24026c561c06dd5bdef6b3", - "sha1": "fdf0d8acd01055f32fb28caee3b5a2d383848e53", - "blobstore_id": "e6a084ab-541c-4f9e-8132-573627bded5a", - "logs": [] - } - ] - }, - "links": { - "http_proxy_with_requires": { - "proxied_http_endpoint": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "listen_port": 15672, - "name_space": { - "fibonacci": "((fibonacci_placeholder))", - "prop_a": "default" - } - } - }, - "proxied_http_endpoint2": { - "instance_group": "provider_deployment_node", - "instances": [ - { - "name": "provider_deployment_node", - "id": "19dea4c6-c25f-478c-893e-db29ba7042b5", - "index": 0, - "bootstrap": true, - "az": "z1", - "address": "192.168.1.10" - } - ], - "properties": { - "a": 1, - "name_space": { - "asdf": "((fibonacci_placeholder))", - "dbxcv": "default" - } - } - } - } - } - } - end - before do - db[:deployments] << {name: 'fake-deployment', id: 42, link_spec_json: link_spec_json.to_json} - db[:variable_sets] << {id: 1, deployment_id: 42, created_at: Time.now} - db[:instances] << { - job: 'provider_instance_group_1', - id: 22, - index: 0, - deployment_id: 42, - state: "started", - variable_set_id: 1, - spec_json: instance_spec_json.to_json - } - DBSpecHelper.migrate(migration_file) - end - - context 'link_providers table' do - context 'when all constraint columns are the same' do - it 'should raise an error' do - expect { db[:link_providers] << {instance_group: 'provider_instance_group_1', deployment_id: 42, type: 'job', name: 'provider_job_1'} } - .to raise_error Sequel::UniqueConstraintViolation - end - end - - context 'when existing record gets updated to violate constraint' do - it 'should raise an error' do - expect { db[:link_providers] << {instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'test', name: 'provider_job_1'} }.to_not raise_error - link_provider = db[:link_providers].where(instance_group: 'provider_instance_group_2', deployment_id: 42, type: 'test', name: 'provider_job_1') - expect { link_provider.update(type: 'job') } - .to raise_error Sequel::UniqueConstraintViolation - end - end - end - - context 'link_consumers table' do - context 'when all constraint columns are the same' do - it 'should raise an error' do - link_consumer = db[:link_consumers].first - expect { db[:link_consumers] << {deployment_id: link_consumer[:deployment_id], instance_group: link_consumer[:instance_group], name: link_consumer[:name], type: link_consumer[:type]} } - .to raise_error Sequel::UniqueConstraintViolation - end - end - - context 'when existing record gets updated to violate constraint' do - it 'should raise an error' do - original_link_consumer = db[:link_consumers].first - expect { db[:link_consumers] << {deployment_id: original_link_consumer[:deployment_id], instance_group: original_link_consumer[:instance_group], name: 'test', type: 'job'} }.to_not raise_error - new_link_consumer = db[:link_consumers].where(deployment_id: original_link_consumer[:deployment_id], instance_group: original_link_consumer[:instance_group], name: 'test', type: 'job') - expect { new_link_consumer.update(name: original_link_consumer[:name]) } - .to raise_error Sequel::UniqueConstraintViolation - end - end - end - - context 'link_provider_intents table' do - context 'when all constraint columns are the same' do - it 'should raise an error' do - link_provider_intent = db[:link_provider_intents].first - expect { db[:link_provider_intents] << {link_provider_id: link_provider_intent[:link_provider_id], original_name: link_provider_intent[:original_name], type: 'job'} } - .to raise_error Sequel::UniqueConstraintViolation - end - end - - context 'when existing record gets updated to violate constraint' do - it 'should raise an error' do - original_link_provider_intents = db[:link_provider_intents].first - expect { db[:link_provider_intents] << {link_provider_id: original_link_provider_intents[:link_provider_id], original_name: 'test-original-name', type: 'test'} }.to_not raise_error - new_link_provider_intents = db[:link_provider_intents].where(link_provider_id: original_link_provider_intents[:link_provider_id], original_name: 'test-original-name', type: 'test') - expect { new_link_provider_intents.update(original_name: original_link_provider_intents[:name]) } - .to raise_error Sequel::UniqueConstraintViolation - end - end - end - - context 'link_consumer_intents table' do - context 'when all constraint columns are the same' do - it 'should raise an error' do - link_consumer_intent = db[:link_consumer_intents].first - expect { db[:link_consumer_intents] << {link_consumer_id: link_consumer_intent[:link_consumer_id], original_name: link_consumer_intent[:original_name], type: 'job'} } - .to raise_error Sequel::UniqueConstraintViolation - end - end - - context 'when existing record gets updated to violate constraint' do - it 'should raise an error' do - original_link_consumer_intents = db[:link_consumer_intents].first - expect { db[:link_consumer_intents] << {link_consumer_id: original_link_consumer_intents[:link_consumer_id], original_name: 'test-original-name', type: 'job'} }.to_not raise_error - new_link_consumer_intents = db[:link_consumer_intents].where(link_consumer_id: original_link_consumer_intents[:link_consumer_id], original_name: 'test-original-name', type: 'job') - expect { new_link_consumer_intents.update(original_name: original_link_consumer_intents[:name]) } - .to raise_error Sequel::UniqueConstraintViolation - end - end - end - - context 'instances_links table' do - context 'when all constraint columns are the same' do - it 'should raise an error' do - instance_link = db[:instances_links].first - expect { db[:instances_links] << {link_id: instance_link[:link_id], instance_id: instance_link[:instance_id]} } - .to raise_error Sequel::UniqueConstraintViolation - end - end - - context 'when existing record gets updated to violate constraint' do - it 'should raise an error' do - existing_link = db[:links].first - db[:links] << {link_provider_intent_id: existing_link[:link_provider_intent_id], link_consumer_intent_id: existing_link[:link_consumer_intent_id], name: 'test', link_content: 'test'} - new_link = db[:links].where(name: 'test', link_content: 'test').first - - original_instances_link = db[:instances_links].first - expect { db[:instances_links] << {link_id: new_link[:id], instance_id: original_instances_link[:instance_id]} }.to_not raise_error - new_instances_link = db[:instances_links].where(link_id: new_link[:id], instance_id: original_instances_link[:instance_id]) - expect { new_instances_link.update(link_id: original_instances_link[:link_id]) } - .to raise_error Sequel::UniqueConstraintViolation - end - end - end - end - - context 'verify unique constraints are named' do - before do - db[:deployments] << {name: 'fake-deployment', id: 42} - DBSpecHelper.migrate(migration_file) - end - - context 'link_providers table' do - it 'has named unique constraint' do - indices = db.indexes(:link_providers) - expect(indices.has_key?(:link_providers_constraint)).to be_truthy - end - end - - context 'link_provider_intents table' do - it 'has named unique constraint' do - indices = db.indexes(:link_provider_intents) - expect(indices.has_key?(:link_provider_intents_constraint)).to be_truthy - end - end - - context 'link_consumers table' do - it 'has named unique constraint' do - indices = db.indexes(:link_consumers) - expect(indices.has_key?(:link_consumers_constraint)).to be_truthy - end - end - - context 'link_consumer_intents table' do - it 'has named unique constraint' do - indices = db.indexes(:link_consumer_intents) - expect(indices.has_key?(:link_consumer_intents_constraint)).to be_truthy - end - end - - context 'instances_links table' do - it 'has named unique constraint' do - indices = db.indexes(:instances_links) - expect(indices.has_key?(:instances_links_constraint)).to be_truthy - end - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171117230219_add_network_spec_to_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171117230219_add_network_spec_to_vms_spec.rb deleted file mode 100644 index 0ac90c07e6a..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171117230219_add_network_spec_to_vms_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'During migrations' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171117230219_add_network_spec_to_vms.rb'} - let(:spec_json) { JSON.dump({'networks' => {'instance-networks' => ['a', 'b']}, 'and-ignored' => 'things'}) } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << {id: 1, name: 'fake-deployment', manifest: '{}'} - db[:variable_sets] << {id: 57, deployment_id: 1, created_at: Time.now} - db[:instances] << {id: 123, availability_zone: 'z1', deployment_id: 1, job: 'instance_job', index: 23, state: 'started', variable_set_id: 57, spec_json: spec_json} - db[:vms] << {instance_id: 123, active: true} - db[:vms] << {instance_id: 123, active: false} - end - - it 'backfills with values for instances where vm was active' do - DBSpecHelper.migrate(migration_file) - - vms = db[:vms].all - vms.sort! { |vm1, vm2| vm1[:id] <=> vm2[:id] } - expect(vms.length).to eq(2) - expect(vms[0][:network_spec_json]).to eq(JSON.dump({'instance-networks' => ['a', 'b']})) - expect(vms[1][:network_spec_json]).to eq(nil) - end - - it 'makes the network_spec_json able to take long strings' do - DBSpecHelper.migrate(migration_file) - - really_long_json_field = "{\"long-value\":\"#{'a' * 65536}}\"" - db[:vms] << {instance_id: 123, network_spec_json: really_long_json_field} - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20171201153629_remove_unused_template_columns_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20171201153629_remove_unused_template_columns_spec.rb deleted file mode 100644 index a3d585258a7..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20171201153629_remove_unused_template_columns_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'Delete column from template table' do - let(:db) {DBSpecHelper.db} - let(:migration_file) {'20171201153629_remove_unused_template_columns.rb'} - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - it 'should remove provides_json column' do - expect(db[:templates].columns.include?(:provides_json)).to be_falsey - end - - it 'should remove consumes_json column' do - expect(db[:templates].columns.include?(:consumes_json)).to be_falsey - end - - it 'should remove properties_json column' do - expect(db[:templates].columns.include?(:properties_json)).to be_falsey - end - - it 'should remove logs_json column' do - expect(db[:templates].columns.include?(:logs_json)).to be_falsey - end - - it 'should remove templates_json column' do - expect(db[:templates].columns.include?(:templates_json)).to be_falsey - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180119183014_add_stemcell_matches_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180119183014_add_stemcell_matches_spec.rb deleted file mode 100644 index e6aca025d35..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180119183014_add_stemcell_matches_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180119183014_add_stemcell_matches.rb' do - let(:db) {DBSpecHelper.db} - - before do - DBSpecHelper.migrate_all_before(subject) - DBSpecHelper.migrate(subject) - end - - it 'creates the table' do - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.19', - cpi: 'aws-use1', - } - - expect(db[:stemcell_matches]).to contain_exactly( - { - id: 1, - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.19', - cpi: 'aws-use1', - } - ) - end - - it 'enforces uniqueness on name+version+cpi' do - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.19', - cpi: 'aws-use1', - } - - expect do - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.19', - cpi: 'aws-use1', - } - end.to raise_error(Sequel::UniqueConstraintViolation) - - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.19', - cpi: 'aws-use2', - } - - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-trusty-go_agent', - version: '3468.20', - cpi: 'aws-use1', - } - - db[:stemcell_matches] << { - name: 'bosh-aws-xen-hvm-ubuntu-xenial-go_agent', - version: '3468.19', - cpi: 'aws-use1', - } - - expect(db[:stemcell_matches].all.length).to eq(4) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses_spec.rb deleted file mode 100644 index efd8b4ce86f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180119233828_add_vm_id_to_ip_addresses_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add vm_id to ip_addresses' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180119233828_add_vm_id_to_ip_addresses.rb' } - let(:instance1) do - { - id: 123, - availability_zone: 'z1', - deployment_id: 1, - job: 'instance_job', - index: 23, - state: 'started', - variable_set_id: 57, - } - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { id: 1, name: 'fake-deployment', manifest: '{}' } - db[:variable_sets] << { id: 57, deployment_id: 1, created_at: Time.now } - db[:instances] << instance1 - db[:vms] << { id: 1, instance_id: 123, active: true } - db[:vms] << { id: 2, instance_id: 123, active: false } - db[:ip_addresses] << { instance_id: 123, address_str: '10.0.0.1' } - db[:ip_addresses] << { instance_id: 123, address_str: '10.1.0.1' } - end - - it 'should add the vm_id column to ip_addresses table' do - DBSpecHelper.migrate(migration_file) - - expect(db[:ip_addresses].columns.include?(:vm_id)).to be_truthy - end - - it 'should backfill vm_id of instances active vm on all up addresses' do - DBSpecHelper.migrate(migration_file) - - db[:ip_addresses].each do |address| - expect(address[:vm_id]).to eq(1) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads_spec.rb deleted file mode 100644 index a1af7ee10ab..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180130182844_rename_stemcell_matches_to_stemcell_uploads_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180130182844_rename_stemcell_matches_to_stemcell_uploads.rb' do - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - it 'renames stemcell_matches table to stemcell_uploads' do - db[:stemcell_matches] << { name: 'stemcell', version: '1.1', cpi: 'aws' } - expect(db[:stemcell_matches].all.count).to eq(1) - - DBSpecHelper.migrate(subject) - - record = db[:stemcell_uploads].all[0] - expect(record[:name]).to eq('stemcell') - expect(record[:version]).to eq('1.1') - expect(record[:cpi]).to eq('aws') - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180130182845_add_team_id_to_configs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180130182845_add_team_id_to_configs_spec.rb deleted file mode 100644 index 3581554e038..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180130182845_add_team_id_to_configs_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add column to configs table' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180130182845_add_team_id_to_configs.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - it 'allows to save team_id' do - DBSpecHelper.migrate(migration_file) - expect(db[:configs].columns).to include(:team_id) - - db[:configs] << { - name: 'config', - type: 'type', - content: '', - created_at: Time.now, - team_id: 1, - } - - expect(db[:configs].first[:team_id]).to eq 1 - end - - it 'allows team_id to be nil' do - DBSpecHelper.migrate(migration_file) - expect(db[:configs].columns).to include(:team_id) - - db[:configs] << { - name: 'config', - type: 'type', - content: '', - created_at: Time.now, - } - - expect(db[:configs].first[:team_id]).to be_nil - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180203000738_create_orphaned_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180203000738_create_orphaned_vms_spec.rb deleted file mode 100644 index b0a4d2c9d47..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180203000738_create_orphaned_vms_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180203000738_create_orphaned_vms.rb' do - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - it 'creates a orphaned vms table' do - DBSpecHelper.migrate(subject) - - db[:orphaned_vms] << { - id: 1, - availability_zone: 'potato', - cid: 'asdf', - cloud_properties: '{"foo":"bar"}', - cpi: 'just-a-cpi', - instance_id: 1, - orphaned_at: Time.now, - } - end - - it 'adds a orphaned_vm_id column to the ip_addresses table' do - DBSpecHelper.migrate(subject) - - expect(db[:ip_addresses].columns.include?(:orphaned_vm_id)).to be_truthy - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180215152554_add_api_version_to_stemcells_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180215152554_add_api_version_to_stemcells_spec.rb deleted file mode 100644 index 0a26969f6d9..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180215152554_add_api_version_to_stemcells_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add api_version column to stemcells' do - let(:db) {DBSpecHelper.db} - let(:migration_file) { '20180215152554_add_api_version_to_stemcells.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - it 'allows to save api_version' do - DBSpecHelper.migrate(migration_file) - expect(db[:stemcells].columns).to include(:api_version) - - db[:stemcells] << { - name: 'ubuntu-stemcell', - version: '3232.43', - cid: '68aab7c44c857217641784806e2eeac4a3a99d1c', - sha1: 'shawone', - operating_system: 'tesseract', - cpi: 'cpi', - api_version: 2, - } - - expect(db[:stemcells].first[:api_version]).to eq 2 - end - - it 'allows api_version to be nil' do - DBSpecHelper.migrate(migration_file) - expect(db[:stemcells].columns).to include(:api_version) - - db[:stemcells] << { - name: 'ubuntu-stemcell', - version: '3232.23', - cid: '68aab7c44c857217641784806e2eeac4a3a99d1c', - sha1: 'shar2d2', - operating_system: 'aether', - cpi: 'cpi', - } - expect(db[:stemcells].first[:api_version]).to be_nil - end - end -end \ No newline at end of file diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms_spec.rb deleted file mode 100644 index 3de09046a0d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180301204622_add_stemcell_api_version_to_vms_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add stemcell api_version to vms and orphaned_vms' do - let(:db) {DBSpecHelper.db} - - let(:migration_file) { '20180301204622_add_stemcell_api_version_to_vms.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - - db[:deployments] << {id: 1, name: 'test-deployment'} - db[:variable_sets] << {id: 1, deployment_id: 1, created_at: Time.now} - db[:variables] << {variable_id: 1, variable_name: "test_variable", variable_set_id: 1} - db[:instances] << {deployment_id: 1, job: 'test-job', index: 1, state: 'test', variable_set_id: 1} - end - - it 'allows to save stemcell_api_version for vms' do - db[:vms] << {id: 1, instance_id: 1} - - DBSpecHelper.migrate(migration_file) - expect(db[:vms].columns).to include(:stemcell_api_version) - - db[:vms] << {id: 2, instance_id: 1} - db[:vms] << {id: 3, instance_id: 1, stemcell_api_version: nil} - db[:vms] << {id: 4, instance_id: 1, stemcell_api_version: 1} - db[:vms] << {id: 5, instance_id: 1, stemcell_api_version: 2} - - expect(db[:vms].where(id: 1).first[:stemcell_api_version]).to eq(nil) - expect(db[:vms].where(id: 2).first[:stemcell_api_version]).to eq(nil) - expect(db[:vms].where(id: 3).first[:stemcell_api_version]).to eq(nil) - expect(db[:vms].where(id: 4).first[:stemcell_api_version]).to eq(1) - expect(db[:vms].where(id: 5).first[:stemcell_api_version]).to eq(2) - end - - it 'allows to save stemcell_api_version for orphaned_vms' do - db[:orphaned_vms] << {id: 1, cid: '1', instance_id: 1, orphaned_at: Time.now} - - DBSpecHelper.migrate(migration_file) - expect(db[:orphaned_vms].columns).to include(:stemcell_api_version) - - db[:orphaned_vms] << {id: 2, cid: '2', instance_id: 1, orphaned_at: Time.now} - db[:orphaned_vms] << {id: 3, cid: '3', instance_id: 1, stemcell_api_version: nil, orphaned_at: Time.now} - db[:orphaned_vms] << {id: 4, cid: '4', instance_id: 1, stemcell_api_version: 1, orphaned_at: Time.now} - db[:orphaned_vms] << {id: 5, cid: '5', instance_id: 1, stemcell_api_version: 2, orphaned_at: Time.now} - - expect(db[:orphaned_vms].where(id: 1).first[:stemcell_api_version]).to eq(nil) - expect(db[:orphaned_vms].where(id: 2).first[:stemcell_api_version]).to eq(nil) - expect(db[:orphaned_vms].where(id: 3).first[:stemcell_api_version]).to eq(nil) - expect(db[:orphaned_vms].where(id: 4).first[:stemcell_api_version]).to eq(1) - expect(db[:orphaned_vms].where(id: 5).first[:stemcell_api_version]).to eq(2) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms_spec.rb deleted file mode 100644 index 8319bc77437..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180405233153_remove_instance_from_orphaned_vms_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180405233153_remove_instance_from_orphaned_vms.rb' do - let(:db) {DBSpecHelper.db} - - before do - DBSpecHelper.migrate_all_before(subject) - end - - it 'remove instance column from orphaned_vms table' do - expect(db[:orphaned_vms].columns.include?(:instance_id)).to be_truthy - DBSpecHelper.migrate(subject) - expect(db[:orphaned_vms].columns.include?(:instance_id)).to be_falsey - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180410180821_migrate_legacy_update_strategy_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180410180821_migrate_legacy_update_strategy_spec.rb deleted file mode 100644 index d73ae1ac9af..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180410180821_migrate_legacy_update_strategy_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180410180821_migrate_legacy_update_strategy.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180410180821_migrate_legacy_update_strategy.rb' } - let(:legacy_spec_json) do - { - 'update' => { - 'strategy' => 'legacy', - }, - }.to_json - end - - let(:create_swap_delete_spec_json) do - { - 'update' => { - 'strategy' => 'hot-swap', - }, - }.to_json - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { id: 1, name: 'fake-deployment-name', manifest: '{}' } - db[:variable_sets] << { id: 100, deployment_id: 1, created_at: Time.now } - db[:instances] << { - id: 1, - job: 'fake-job', - index: 1, - deployment_id: 1, - variable_set_id: 100, - state: 'started', - spec_json: legacy_spec_json, - } - db[:instances] << { - id: 2, - job: 'fake-job', - index: 1, - deployment_id: 1, - variable_set_id: 100, - state: 'started', - spec_json: create_swap_delete_spec_json, - } - end - - it 'should update the update strategies to their valid names' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - updated_legacy_spec_json = JSON.parse(db[:instances].all[0][:spec_json]) - expect(updated_legacy_spec_json['update']['strategy']).to eq('delete-create') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['strategy']).to eq('create-swap-delete') - end - - context 'with invalid json' do - let(:legacy_spec_json) { '{{' } - - it 'moves on to the next records' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - expect(db[:instances].all[0][:spec_json]).to eq('{{') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['strategy']).to eq('create-swap-delete') - end - end - - context 'when the update key does not exist' do - let(:legacy_spec_json) { '{}' } - - it 'does not migrate that spec_json' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - expect(db[:instances].all[0][:spec_json]).to eq('{}') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['strategy']).to eq('create-swap-delete') - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy_spec.rb deleted file mode 100644 index bfcf88b8665..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180411165035_migrate_update_strategy_to_vm_strategy_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180411165035_migrate_update_strategy_to_vm_strategy.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180411165035_migrate_update_strategy_to_vm_strategy.rb' } - let(:legacy_spec_json) do - { - 'update' => { - 'strategy' => 'delete-create', - }, - }.to_json - end - - let(:create_swap_delete_spec_json) do - { - 'update' => { - 'strategy' => 'create-swap-delete', - }, - }.to_json - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { id: 1, name: 'fake-deployment-name', manifest: '{}' } - db[:variable_sets] << { id: 100, deployment_id: 1, created_at: Time.now } - db[:instances] << { - id: 1, - job: 'fake-job', - index: 1, - deployment_id: 1, - variable_set_id: 100, - state: 'started', - spec_json: legacy_spec_json, - } - db[:instances] << { - id: 2, - job: 'fake-job', - index: 1, - deployment_id: 1, - variable_set_id: 100, - state: 'started', - spec_json: create_swap_delete_spec_json, - } - end - - it 'should update the update strategies to their valid names' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - updated_legacy_spec_json = JSON.parse(db[:instances].all[0][:spec_json]) - expect(updated_legacy_spec_json['update']['vm_strategy']).to eq('delete-create') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['vm_strategy']).to eq('create-swap-delete') - end - - context 'with invalid json' do - let(:legacy_spec_json) { '{{' } - - it 'moves on to the next records' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - expect(db[:instances].all[0][:spec_json]).to eq('{{') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['vm_strategy']).to eq('create-swap-delete') - end - end - - context 'when the update key does not exist' do - let(:legacy_spec_json) { '{}' } - - it 'does not migrate that spec_json' do - DBSpecHelper.migrate(migration_file) - - expect(db[:instances].count).to eq(2) - expect(db[:instances].all[0][:spec_json]).to eq('{}') - updated_create_swap_delete_spec_json = JSON.parse(db[:instances].all[1][:spec_json]) - expect(updated_create_swap_delete_spec_json['update']['vm_strategy']).to eq('create-swap-delete') - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms_spec.rb deleted file mode 100644 index 0cf355d0725..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180427184448_add_historical_metadata_to_orphaned_vms_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'add historical metadata to orphaned vms' do - let(:db) { DBSpecHelper.db } - - let(:migration_file) { '20180427184448_add_historical_metadata_to_orphaned_vms.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - it 'adds deployment_name and instance_name to orphaned_vms' do - expect(db[:orphaned_vms].columns).to include(:deployment_name) - expect(db[:orphaned_vms].columns).to include(:instance_name) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180515204145_add_vm_metadata_spec_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180515204145_add_vm_metadata_spec_spec.rb deleted file mode 100644 index 90e681609c9..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180515204145_add_vm_metadata_spec_spec.rb +++ /dev/null @@ -1,94 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180515204145_add_vm_metadata_spec.rb' do - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180515204145_add_vm_metadata_spec.rb' } - - let(:spec_json) do - JSON.dump( - 'stemcells' => { - 'name' => 'foostemcell', - 'version' => '1', - }, - 'networks' => { 'instance-networks' => %w[a b] }, - 'env' => { 'some-env' => 'some-env-value' }, - 'vm_type' => { - 'cloud_properties' => { - 'a' => 'b', - }, - }, - ) - end - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { id: 1, name: 'fake-deployment', manifest: '{}' } - db[:variable_sets] << { id: 57, deployment_id: 1, created_at: Time.now } - db[:instances] << { - id: 123, - availability_zone: 'z1', - deployment_id: 1, - job: 'instance_job', - index: 23, - state: 'started', - variable_set_id: 57, - spec_json: spec_json, - } - db[:vms] << { instance_id: 123, active: true } - db[:vms] << { instance_id: 123, active: false } - end - - it 'backfills with values for instances where vm was active' do - DBSpecHelper.migrate(migration_file) - - vms = db[:vms].all - expect(vms[0][:stemcell_name]).to eq('foostemcell') - expect(vms[1][:stemcell_name]).to eq('foostemcell') - expect(vms[0][:stemcell_version]).to eq('1') - expect(vms[1][:stemcell_version]).to eq('1') - expect(vms[0][:env_json]).to eq(JSON.dump('some-env' => 'some-env-value')) - expect(vms[1][:env_json]).to eq(JSON.dump('some-env' => 'some-env-value')) - expect(vms[0][:cloud_properties_json]).to eq(JSON.dump('a' => 'b')) - expect(vms[1][:cloud_properties_json]).to eq(JSON.dump('a' => 'b')) - end - - it 'makes the env_json able to take long strings' do - DBSpecHelper.migrate(migration_file) - - really_long_json_field = "{\"long-value\":\"#{'a' * 65_536}}\"" - db[:vms] << { instance_id: 123, env_json: really_long_json_field } - end - - it 'makes the cloud_properties_json able to take long strings' do - DBSpecHelper.migrate(migration_file) - - really_long_json_field = "{\"long-value\":\"#{'a' * 65_536}}\"" - db[:vms] << { instance_id: 123, cloud_properties_json: really_long_json_field } - end - - it 'gracefully handles nil values' do - db[:instances] << { - id: 124, - availability_zone: 'z1', - deployment_id: 1, - job: 'instance_job', - index: 23, - state: 'started', - variable_set_id: 57, - spec_json: nil, - } - db[:vms] << { instance_id: 124, active: true } - db[:vms] << { instance_id: 124, active: false } - - DBSpecHelper.migrate(migration_file) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180613190204_links_api_longtext_support_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180613190204_links_api_longtext_support_spec.rb deleted file mode 100644 index 0404227f3c2..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180613190204_links_api_longtext_support_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20180613190204_links_api_longtext_support.rb' do - let(:db) { DBSpecHelper.db } - - let(:migration_file) { '20180613190204_links_api_longtext_support.rb' } - before do - DBSpecHelper.migrate_all_before(migration_file) - DBSpecHelper.migrate(migration_file) - end - - context 'link provider metadata is very long (>255)' do - it 'does not truncate metadata contents' do - db[:deployments] << { name: 'fake-deployment', id: 42 } - db[:link_providers] << { - id: 5, - deployment_id: 42, - instance_group: 'baz', - name: 'foo', - type: 'bar', - serial_id: 12, - } - - metadata = 'a' * 1000 - - db[:link_provider_intents] << { - id: 7, - link_provider_id: 5, - original_name: 'original_name', - type: 'foobar', - name: 'some_name', - metadata: metadata, - } - - expect(db[:link_provider_intents].where(id: 7).first[:metadata]).to eq(metadata) - end - end - - context 'link consumer metadata is very long (>255)' do - it 'does not truncate metadata contents' do - db[:deployments] << { name: 'fake-deployment', id: 42 } - db[:link_consumers] << { - id: 5, - deployment_id: 42, - instance_group: 'baz', - name: 'foo', - type: 'bar', - serial_id: 12, - } - - metadata = 'a' * 1000 - - db[:link_consumer_intents] << { - id: 7, - link_consumer_id: 5, - original_name: 'original_name', - type: 'foobar', - name: 'some_name', - metadata: metadata, - } - - expect(db[:link_consumer_intents].where(id: 7).first[:metadata]).to eq(metadata) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20180822230006_create_network_table_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20180822230006_create_network_table_spec.rb deleted file mode 100644 index eb51c3973f7..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20180822230006_create_network_table_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe 'create_managed_network_tables' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20180822230006_create_network_table.rb' } - let(:created_at) { Time.now.utc } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:deployments] << { - id: 42, - name: 'fake_deployment', - } - - db[:deployments] << { - id: 28, - name: 'fake_deployment_2', - } - end - - it 'creates all tables for managed networks' do - DBSpecHelper.migrate(migration_file) - - db[:networks] << { - name: 'test_network_1', - type: 'manual', - created_at: created_at, - } - - record = db[:networks].first - expect(record[:created_at]).to_not be_nil - expect(record[:id]).to eq(1) - expect(record[:name]).to eq('test_network_1') - expect(record[:type]).to eq('manual') - expect(record[:orphaned]).to eq(false) - expect(record[:orphaned_at]).to be_nil - - db[:subnets] << { - cid: 'subnetid-12345', - name: 'subnet-1', - cpi: 'vsphere', - cloud_properties: '{"name": "subnet-name"}', - network_id: 1, - reserved: '["192.168.10.2", "192.168.10.3"]', - range: '192.168.10.10/24', - gateway: '192.168.10.1', - } - - expect(db[:subnets].first).to eq( - id: 1, - cid: 'subnetid-12345', - name: 'subnet-1', - cpi: 'vsphere', - cloud_properties: '{"name": "subnet-name"}', - network_id: 1, - range: '192.168.10.10/24', - reserved: '["192.168.10.2", "192.168.10.3"]', - gateway: '192.168.10.1', - ) - - db[:deployments_networks] << { - deployment_id: 42, - network_id: 1, - } - - expect(db[:deployments_networks].first).to eq( - deployment_id: 42, - network_id: 1, - ) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group_spec.rb deleted file mode 100644 index cd9b9acbf79..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20181017210108_add_type_to_local_dns_encoded_instance_group_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20181017210108_add_type_to_local_dns_encoded_instance_group.rb' do - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - it 'has a unique index on type, name, and deployment_id' do - DBSpecHelper.migrate(subject) - db[:deployments] << { - id: 1, - name: 'foo', - } - db[:local_dns_encoded_instance_groups] << { - type: 'foo-type', - name: 'foo-name', - deployment_id: 1, - } - expect do - db[:local_dns_encoded_instance_groups] << { - type: 'foo-type', - name: 'foo-name', - deployment_id: 1, - } - end.to raise_error(Sequel::UniqueConstraintViolation) - end - - it 'updates existing records to type instance-group' do - db[:deployments] << { - id: 1, - name: 'foo', - } - db[:local_dns_encoded_instance_groups] << { - name: 'foo-name', - deployment_id: 1, - } - db[:local_dns_encoded_instance_groups] << { - name: 'foo-name-2', - deployment_id: 1, - } - - DBSpecHelper.migrate(subject) - - db[:local_dns_encoded_instance_groups].all.each do |rec| - expect(rec[:type]).to eq('instance-group') - end - end - - it 'defaults type to instance-group' do - DBSpecHelper.migrate(subject) - db[:deployments] << { - id: 1, - name: 'foo', - } - - db[:local_dns_encoded_instance_groups] << { - name: 'foo-name', - deployment_id: 1, - } - expect(db[:local_dns_encoded_instance_groups].first[:type]).to eq 'instance-group' - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190104135624_add_update_completed_to_release_versions_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190104135624_add_update_completed_to_release_versions_spec.rb deleted file mode 100644 index 6ebcb1e4147..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190104135624_add_update_completed_to_release_versions_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190104135624_add_update_completed_to_release_versions.rb' do - let(:migration_file) { '20190104135624_add_update_completed_to_release_versions.rb' } - - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(migration_file) - - db[:releases] << { name: 'rel1' } - db[:releases] << { name: 'rel2' } - end - - it 'defaults update_completed to true' do - db[:release_versions] << { id: 100, version: 'ver1', release_id: 1, commit_hash: 'uuid-1', uncommitted_changes: false } - db[:release_versions] << { id: 200, version: 'ver2', release_id: 2, commit_hash: 'uuid-2', uncommitted_changes: false } - - DBSpecHelper.migrate(migration_file) - - expect(db[:release_versions].columns).to include(:update_completed) - - expect(db[:release_versions].where(id: 100).first[:update_completed]).to eq(true) - expect(db[:release_versions].where(id: 200).first[:update_completed]).to eq(true) - end - - it 'add entries with optional update_completed and still defaults it to true' do - DBSpecHelper.migrate(migration_file) - - expect(db[:release_versions].columns).to include(:update_completed) - - db[:release_versions] << { id: 300, version: 'ver1', release_id: 1, commit_hash: 'uuid-1', uncommitted_changes: false, update_completed: true } - db[:release_versions] << { id: 400, version: 'ver2', release_id: 2, commit_hash: 'uuid-2', uncommitted_changes: false } - - expect(db[:release_versions].where(id: 300).first[:update_completed]).to eq(true) - expect(db[:release_versions].where(id: 400).first[:update_completed]).to eq(false) - end - - it 'fail when adding null value for update_completed' do - DBSpecHelper.migrate(migration_file) - - expect { - db[:release_versions] << { id: 500, version: 'ver1', release_id: 1, commit_hash: 'uuid-1', uncommitted_changes: false, update_completed: nil } - }.to raise_error Sequel::NotNullConstraintViolation - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190114153103_add_index_to_tasks_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190114153103_add_index_to_tasks_spec.rb deleted file mode 100644 index 3672a082d10..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190114153103_add_index_to_tasks_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190114153103_add_index_to_tasks.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190114153103_add_index_to_tasks.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:tasks] << { id: 1, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - db[:tasks] << { id: 2, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - db[:tasks] << { id: 3, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - end - - context 'before migration' do - it 'should NOT have indexes associated with tasks table' do - expect(db.indexes(:tasks)).to_not have_key(:tasks_type_index) - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - it 'should add index to type aft' do - expect(db.indexes(:tasks)).to have_key(:tasks_type_index) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs_spec.rb deleted file mode 100644 index 97ebcf0a73f..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190313231924_remove_constraints_from_local_dns_blobs_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190313231924_remove_constraints_from_local_dns_blobs.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190313231924_remove_constraints_from_local_dns_blobs.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - db[:tasks] << { id: 1, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - db[:tasks] << { id: 2, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - db[:tasks] << { id: 3, state: 'alabama', timestamp: '2016-04-14 11:53:42', description: 'descr', type: 'type' } - end - - context 'before migration' do - it 'should NOT allow empty records in local_dns_blobs' do - DBSpecHelper.skip_on_mysql(self, 'NULL constraint violations not generated') - - expect { db[:local_dns_blobs] << {} }.to raise_error Sequel::NotNullConstraintViolation - expect(db[:local_dns_blobs].count).to eq(0) - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'should allow empty records in local_dns_blobs' do - expect { db[:local_dns_blobs] << {} }.not_to raise_error - expect(db[:local_dns_blobs].count).to eq(1) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs_spec.rb deleted file mode 100644 index 47412d439bf..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190314182109_add_records_version_to_local_dns_blobs_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190314182109_add_records_version_to_local_dns_blobs.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190314182109_add_records_version_to_local_dns_blobs.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - context 'before migration' do - it 'should NOT have records_version in local_dns_blobs' do - expect(db[:local_dns_blobs].columns).to_not include(:records_version) - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'should have records_version in local_dns_blobs' do - expect(db[:local_dns_blobs].columns).to include(:records_version) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190314192454_create_local_dns_aliases_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190314192454_create_local_dns_aliases_spec.rb deleted file mode 100644 index 7c89db331f0..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190314192454_create_local_dns_aliases_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190314192454_create_local_dns_aliases.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190314192454_create_local_dns_aliases.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - context 'before migration' do - it 'should NOT have a local_dns_aliases table' do - expect { db[:local_dns_aliases] << {} }.to raise_error Sequel::DatabaseError - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'should have a local_dns_aliases table' do - expect { db[:local_dns_aliases] << {} }.not_to raise_error - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs_spec.rb deleted file mode 100644 index b16798ed102..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190315163632_add_aliases_version_to_local_dns_blobs_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190315163632_add_aliases_version_to_local_dns_blobs.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190315163632_add_aliases_version_to_local_dns_blobs.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - context 'before migration' do - it 'should NOT have aliases_version in local_dns_blobs' do - expect(db[:local_dns_blobs].columns).to_not include(:aliases_version) - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'should have aliases_version in local_dns_blobs' do - expect(db[:local_dns_blobs].columns).to include(:aliases_version) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases_spec.rb deleted file mode 100644 index eab2c301f3d..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190318234554_add_criteria_columns_to_local_dns_aliases_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190318234554_add_criteria_columns_to_local_dns_aliases.rb' do - let(:db) { DBSpecHelper.db } - let(:migration_file) { '20190318234554_add_criteria_columns_to_local_dns_aliases.rb' } - - before do - DBSpecHelper.migrate_all_before(migration_file) - end - - context 'before migration' do - it 'should NOT have criteria columns in local_dns_aliases' do - expect(db[:local_dns_aliases].columns).to_not include(:health_filter) - expect(db[:local_dns_aliases].columns).to_not include(:placeholder_type) - expect(db[:local_dns_aliases].columns).to_not include(:initial_health_check) - expect(db[:local_dns_aliases].columns).to_not include(:group_id) - expect(db[:local_dns_aliases].columns).to include(:target) - end - end - - context 'after migration' do - before do - DBSpecHelper.migrate(migration_file) - end - - it 'should have criteria columns in local_dns_aliases' do - expect(db[:local_dns_aliases].columns).to include(:health_filter) - expect(db[:local_dns_aliases].columns).to include(:placeholder_type) - expect(db[:local_dns_aliases].columns).to include(:initial_health_check) - expect(db[:local_dns_aliases].columns).to include(:group_id) - expect(db[:local_dns_aliases].columns).not_to include(:target) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190325095716_remove_resurrection_paused_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190325095716_remove_resurrection_paused_spec.rb deleted file mode 100644 index 2b32ffc8afd..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190325095716_remove_resurrection_paused_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190325095716_remove_resurrection_paused.rb' do - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - it 'drops resurrection_paused column from instances table' do - expect(db[:instances].columns.include?(:resurrection_paused)).to be_truthy - DBSpecHelper.migrate(subject) - expect(db[:instances].columns.include?(:resurrection_paused)).to be_falsey - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/20190327222054_scale_dns_blob_version_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/20190327222054_scale_dns_blob_version_spec.rb deleted file mode 100644 index 4c0f5751e16..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/20190327222054_scale_dns_blob_version_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../../../../db_spec_helper' - -module Bosh::Director - describe '20190327222054_scale_dns_blob_version.rb' do - subject(:migration) { '20190327222054_scale_dns_blob_version.rb' } - let(:db) { DBSpecHelper.db } - - before do - DBSpecHelper.migrate_all_before(subject) - end - - context 'when adding new blob records' do - before do - db[:local_dns_blobs] << { version: 90 } - end - - it 'makes it so new blob ids are greater than any version that existed before' do - DBSpecHelper.migrate(subject) - db[:local_dns_blobs] << {} - expect(db[:local_dns_blobs].max(:id)).to be >= db[:local_dns_blobs].max(:version) - end - - it 'does not change the number of rows in local_dns_blobs' do - expect { DBSpecHelper.migrate(subject) }.not_to(change { db[:local_dns_blobs].count }) - end - end - - context 'when migrating an empty db' do - it 'does nothing' do - expect { DBSpecHelper.migrate(subject) }.not_to(change { db[:local_dns_blobs].count }) - end - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/director/verify_migration_digest_spec.rb b/src/bosh-director/spec/unit/db/migrations/director/verify_migration_digest_spec.rb deleted file mode 100644 index 6aa645a8e32..00000000000 --- a/src/bosh-director/spec/unit/db/migrations/director/verify_migration_digest_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'db_spec_helper' -require 'json' -require 'digest/sha1' - -module Bosh::Director - describe 'migration files' do - let(:expected_digests) { JSON.load_file(DBSpecHelper.director_migrations_digest_file)} - let(:actual_digests) do - DBSpecHelper.get_migrations.each_with_object({}) do |migration, hash| - hash[File.basename(migration, '.rb')] = Digest::SHA1.hexdigest(File.read(migration)) - end - end - - it 'should have the same digest as the one that was previously recorded' do - expect(expected_digests).to eq(actual_digests) - end - end -end diff --git a/src/bosh-director/spec/unit/db/migrations/verify_migration_digest_spec.rb b/src/bosh-director/spec/unit/db/migrations/verify_migration_digest_spec.rb new file mode 100644 index 00000000000..762d0418c98 --- /dev/null +++ b/src/bosh-director/spec/unit/db/migrations/verify_migration_digest_spec.rb @@ -0,0 +1,41 @@ +require 'db_migrator' +require 'json' +require 'digest/sha1' + +module Bosh::Director + describe 'migration files' do + let(:expected_digests) do + [ + { + filename: '20110209010747_initial.rb', + sha1: 'c9b5654ce0a4a5df4805a2acec301fc65e0fd310', + }, + { + filename: '20210902232124_add_blobstore_and_nats_shas_to_vms.rb', + sha1: '7710e2c2c9589865382daaa456bd0e95b22ba3b6', + }, + { + filename: '20230103143246_add_permanent_nats_credentials_to_vms.rb', + sha1: 'a01b24aa3891d6bb0eb4e4032553d4e9871a19e0', + }, + { + filename: '20240319204601_remove_dns_records_from_instances.rb', + sha1: 'bb637d410772d09caabdb68a1126fbc9f9b4deec', + }, + ] + end + + let(:actual_digests) do + Dir.glob(File.join(DBMigrator::MIGRATIONS_DIR, '*.rb')).map do |migration| + { + filename: File.basename(migration), + sha1: Digest::SHA1.hexdigest(File.read(migration)), + } + end + end + + it 'should have the same digest as the one that was previously recorded' do + expect(expected_digests).to eq(actual_digests) + end + end +end diff --git a/src/bosh-director/spec/unit/db/migrations/validate_mysql_column_type_spec.rb b/src/bosh-director/spec/unit/db/validate_mysql_column_type_spec.rb similarity index 100% rename from src/bosh-director/spec/unit/db/migrations/validate_mysql_column_type_spec.rb rename to src/bosh-director/spec/unit/db/validate_mysql_column_type_spec.rb diff --git a/src/bosh-director/spec/unit/db_migrator_spec.rb b/src/bosh-director/spec/unit/db_migrator_spec.rb index 1c07041c0e0..9e6f5e3d6af 100644 --- a/src/bosh-director/spec/unit/db_migrator_spec.rb +++ b/src/bosh-director/spec/unit/db_migrator_spec.rb @@ -4,7 +4,7 @@ module Bosh::Director describe 'DBMigrator' do let(:db) { instance_double(Sequel::Database) } - let(:options) { { target: 15, current: 10 } } + let(:options) { { allow_missing_migration_files: true, target: 15, current: 10 } } let(:retry_interval_override) { 0.01 } subject(:db_migrator) { DBMigrator.new(db, options, retry_interval_override) }