Example #1
0
        public void SchemaMigration_DeleteUnusedColumns()
        {
            using (var db = new SQLiteDatabase(":memory:"))
            {
                db.SynchronizeSchema <Customer1>();
                var table = db.GetTable("Customer");
                Assert.AreEqual(nameof(SQLiteColumnType.INTEGER), table.GetColumn("Id").Type);
                Assert.AreEqual(nameof(SQLiteColumnType.TEXT), table.GetColumn("Name").Type);

                var saveOptions = db.CreateSaveOptions();
                saveOptions.DeleteUnusedColumns = true;
                db.SynchronizeSchema <Customer2>(saveOptions);
                table = db.GetTable("Customer");
                Assert.AreEqual(3, table.Columns.Count);
                Assert.AreEqual(nameof(SQLiteColumnType.INTEGER), table.GetColumn("Id").Type);
                Assert.AreEqual(nameof(SQLiteColumnType.TEXT), table.GetColumn("FirstName").Type);
                Assert.AreEqual(nameof(SQLiteColumnType.TEXT), table.GetColumn("LastName").Type);
            }
        }