Example #1
0
func AppendMigration(migration migration.Migration) {
	for _, m := range Migrations {
		if m.Version() == migration.Version() {
			panic("cannot have two migrations with the same version")
		}
	}

	Migrations = append(Migrations, migration)
}
		fakeClock = fakeclock.NewFakeClock(time.Now())
		rawSQLDB.Exec("DROP TABLE domains;")
		rawSQLDB.Exec("DROP TABLE tasks;")
		rawSQLDB.Exec("DROP TABLE desired_lrps;")
		rawSQLDB.Exec("DROP TABLE actual_lrps;")

		mig = migrations.NewAddPlacementTagsToDesiredLRPs()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(mig))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(mig.Version()).To(BeEquivalentTo(1472757022))
		})
	})

	Describe("Up", func() {
		var initialMigrations migration.Migrations

		BeforeEach(func() {
			initialMigrations = []migration.Migration{
				migrations.NewETCDToSQL(),
				migrations.NewIncreaseRunInfoColumnSize(),
			}

			for _, m := range initialMigrations {
				m.SetRawSQLDB(rawSQLDB)
				m.SetDBFlavor(flavor)
		encryptionKey, err := encryption.NewKey("label", "passphrase")
		Expect(err).NotTo(HaveOccurred())
		keyManager, err := encryption.NewKeyManager(encryptionKey, nil)
		Expect(err).NotTo(HaveOccurred())
		cryptor = encryption.NewCryptor(keyManager, rand.Reader)
		serializer = format.NewSerializer(cryptor)
		migration = migrations.NewBase64ProtobufEncode()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(migration))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1441411196))
		})
	})

	Describe("Up", func() {
		var (
			expectedDesiredLRP                             *models.DesiredLRP
			expectedActualLRP, expectedEvacuatingActualLRP *models.ActualLRP
			expectedTask                                   *models.Task
			migrationErr                                   error
		)

		BeforeEach(func() {
			// DesiredLRP
			expectedDesiredLRP = model_helpers.NewValidDesiredLRP("process-guid")
			jsonValue, err := json.Marshal(expectedDesiredLRP)
			rawSQLDB.Exec("DROP TABLE domains;")
			rawSQLDB.Exec("DROP TABLE tasks;")
			rawSQLDB.Exec("DROP TABLE desired_lrps;")
			rawSQLDB.Exec("DROP TABLE actual_lrps;")

			migration = migrations.NewIncreaseRunInfoColumnSize()
			serializer = format.NewSerializer(cryptor)
		})

		It("appends itself to the migration list", func() {
			Expect(migrations.Migrations).To(ContainElement(migration))
		})

		Describe("Version", func() {
			It("returns the timestamp from which it was created", func() {
				Expect(migration.Version()).To(BeEquivalentTo(1471030898))
			})
		})

		Describe("Up", func() {
			BeforeEach(func() {
				// Can't do this in the Describe BeforeEach
				// as the test on line 37 will cause ginkgo to panic
				migration.SetRawSQLDB(rawSQLDB)
				migration.SetDBFlavor(flavor)
			})

			JustBeforeEach(func() {
				migrationErr = migration.Up(logger)
			})
		Expect(err).NotTo(HaveOccurred())
		keyManager, err := encryption.NewKeyManager(encryptionKey, nil)
		Expect(err).NotTo(HaveOccurred())
		cryptor = encryption.NewCryptor(keyManager, rand.Reader)
		serializer = format.NewSerializer(cryptor)
		migration = migrations.NewTimeoutMilliseconds()
		db = etcddb.NewETCD(format.ENCRYPTED_PROTO, 1, 1, 1*time.Minute, cryptor, storeClient, fakeClock)
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(migration))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1451635200))
		})
	})

	Describe("Down", func() {
		It("returns a not implemented error", func() {
			Expect(migration.Down(logger)).To(HaveOccurred())
		})
	})

	Describe("Up", func() {
		var (
			task         *models.Task
			migrationErr error
		)
		fakeClock = fakeclock.NewFakeClock(time.Now())
		rawSQLDB.Exec("DROP TABLE domains;")
		rawSQLDB.Exec("DROP TABLE tasks;")
		rawSQLDB.Exec("DROP TABLE desired_lrps;")
		rawSQLDB.Exec("DROP TABLE actual_lrps;")

		mig = migrations.NewAddMaxPidsToDesiredLRPs()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(mig))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(mig.Version()).To(BeEquivalentTo(1481761088))
		})
	})

	Describe("Up", func() {
		var initialMigrations migration.Migrations

		BeforeEach(func() {
			initialMigrations = []migration.Migration{
				migrations.NewETCDToSQL(),
				migrations.NewIncreaseRunInfoColumnSize(),
			}

			for _, m := range initialMigrations {
				m.SetRawSQLDB(rawSQLDB)
				m.SetDBFlavor(flavor)
			rawSQLDB.Exec("DROP TABLE domains;")
			rawSQLDB.Exec("DROP TABLE tasks;")
			rawSQLDB.Exec("DROP TABLE desired_lrps;")
			rawSQLDB.Exec("DROP TABLE actual_lrps;")

			migration = migrations.NewIncreaseErrorColumnsSize()
			serializer = format.NewSerializer(cryptor)
		})

		It("appends itself to the migration list", func() {
			Expect(migrations.Migrations).To(ContainElement(migration))
		})

		Describe("Version", func() {
			It("returns the timestamp from which it was created", func() {
				Expect(migration.Version()).To(BeEquivalentTo(1474908092))
			})
		})

		Describe("Up", func() {
			BeforeEach(func() {
				// Can't do this in the Describe BeforeEach
				// as the test on line 37 will cause ginkgo to panic
				migration.SetRawSQLDB(rawSQLDB)
				migration.SetDBFlavor(flavor)
			})

			JustBeforeEach(func() {
				migrationErr = migration.Up(logger)
				Expect(migrationErr).NotTo(HaveOccurred())
			})
		migration migration.Migration
		logger    *lagertest.TestLogger
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		migration = migrations.NewAddCachedDependencies()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(migration))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1450292094))
		})
	})

	Describe("Up", func() {
		It("returns nil", func() {
			migrationErr := migration.Up(logger)
			Expect(migrationErr).NotTo(HaveOccurred())
		})
	})

	Describe("Down", func() {
		It("returns a not implemented error", func() {
			Expect(migration.Down(logger)).To(HaveOccurred())
		})
	})
		migration = migrations.NewETCDToSQL()
		serializer = format.NewSerializer(cryptor)

		rawSQLDB.Exec("DROP TABLE domains;")
		rawSQLDB.Exec("DROP TABLE tasks;")
		rawSQLDB.Exec("DROP TABLE desired_lrps;")
		rawSQLDB.Exec("DROP TABLE actual_lrps;")
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(migration))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(migration.Version()).To(BeEquivalentTo(1461790966))
		})
	})

	Describe("Up", func() {
		JustBeforeEach(func() {
			migration.SetStoreClient(storeClient)
			migration.SetRawSQLDB(rawSQLDB)
			migration.SetCryptor(cryptor)
			migration.SetClock(fakeClock)
			migration.SetDBFlavor(flavor)
			migrationErr = migration.Up(logger)
		})

		Context("when there is existing data in the database", func() {
			BeforeEach(func() {
		fakeClock = fakeclock.NewFakeClock(time.Now())
		rawSQLDB.Exec("DROP TABLE domains;")
		rawSQLDB.Exec("DROP TABLE tasks;")
		rawSQLDB.Exec("DROP TABLE desired_lrps;")
		rawSQLDB.Exec("DROP TABLE actual_lrps;")

		mig = migrations.NewEncryptRoutes()
	})

	It("appends itself to the migration list", func() {
		Expect(migrations.Migrations).To(ContainElement(mig))
	})

	Describe("Version", func() {
		It("returns the timestamp from which it was created", func() {
			Expect(mig.Version()).To(BeEquivalentTo(1474993971))
		})
	})

	Describe("Up", func() {
		var initialMigrations migration.Migrations
		var routes string

		BeforeEach(func() {
			initialMigrations = []migration.Migration{
				migrations.NewETCDToSQL(),
				migrations.NewIncreaseRunInfoColumnSize(),
				migrations.NewAddPlacementTagsToDesiredLRPs(),
				migrations.NewIncreaseErrorColumnsSize(),
			}