diff options
| author | Teddy Wing | 2017-09-25 17:49:24 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-09-25 17:49:24 +0200 |
| commit | c4d4474963d7362ed1e58644d4ea61232d287449 (patch) | |
| tree | 6cbaf6750052185d2f0661e8c36748436a0c7c6e | |
| parent | e9a87b0fcc7c41174f50033f045c789f6a00f22f (diff) | |
| download | chouette-core-c4d4474963d7362ed1e58644d4ea61232d287449.tar.bz2 | |
Add data migration to give all Workbenches a ReferentialSuite
Existing `Workbench`es don't have associated `ReferentialSuite`s in
their `output` fields. The new requirement is that all `Workbench`es
must have a `ReferentialSuite`.
To enforce this for existing `Workbench` records, this data migration
creates new (empty) `ReferentialSuite`s for each existing `Workbench`.
Not performant at all, and I'm worried I'm missing some edge case, but
this is the gist of it.
Refs #3520
| -rw-r--r-- | db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb | 12 | ||||
| -rw-r--r-- | db/schema.rb | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb b/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb new file mode 100644 index 000000000..530850a5a --- /dev/null +++ b/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb @@ -0,0 +1,12 @@ +class CreateReferentialSuiteForEachExistingWorkbench < ActiveRecord::Migration + def up + Workbench.where(output: nil).each do |workbench| + workbench.output = ReferentialSuite.create + workbench.save + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index e7efce531..c95280051 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170925123159) do +ActiveRecord::Schema.define(version: 20170925154017) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |
