Ejemplo n.º 1
0
        public void TestSequence()
        {
            var context = new MsSqlTestSqlDataContext();

            DropDatabase(context);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var provider         = Resolver.Get <ITransactStoreProvider <MsSqlTestTypesModel> >();
            var relationProvider = Resolver.Get <ITransactStoreProvider <MsSqlTestRelationsModel> >();

            TestModelMethods.TestSequence(provider, relationProvider);

            const string changeColumn = "ALTER TABLE [TestTypes] ALTER COLUMN [Int32Thing] bigint NULL";
            const string addColumn    = "ALTER TABLE [TestTypes] ADD [DummyToMakeNullable] int NOT NULL";
            const string dropColumn   = "ALTER TABLE [TestTypes] DROP COLUMN [ByteThing]";

            ExecuteSql(context, changeColumn);
            ExecuteSql(context, addColumn);
            ExecuteSql(context, dropColumn);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var sb           = new StringBuilder();
            var modelDetails = ModelAnalyzer.GetModel <MsSqlTestTypesModel>();

            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                sb.Append("ALTER TABLE [TestTypes] DROP COLUMN [").Append(property.PropertySourceName).Append("]\r\n");
            }
            var dropAllColumns = sb.ToString();

            ExecuteSql(context, dropAllColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            sb.Clear();
            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                if (property.IsNullable)
                {
                    sb.Append("ALTER TABLE [TestTypes] ADD [Junk").Append(property.PropertySourceName).Append("] ");
                    MsSql.MsSqlEngine.WriteSqlTypeFromModel(sb, property, true);
                    sb.Insert(sb.Length - 4, "NOT ");
                    sb.Append("\r\n");
                }
            }
            var addJunkColumns = sb.ToString();

            ExecuteSql(context, addJunkColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);
        }
Ejemplo n.º 2
0
        public void TestSequence()
        {
            var context = new PostgreSqlTestSqlDataContext();

            DropDatabase(context);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var provider         = Resolver.Get <ITransactStoreProvider <PostgreSqlTestTypesModel> >();
            var relationProvider = Resolver.Get <ITransactStoreProvider <PostgreSqlTestRelationsModel> >();

            TestModelMethods.TestSequence(provider, relationProvider);

            const string changeColumn = "ALTER TABLE testtypes ALTER COLUMN int32thing TYPE bigint; ALTER TABLE testtypes ALTER COLUMN int32thing DROP NOT NULL;";
            const string addColumn    = "ALTER TABLE testtypes ADD dummytomakenullable int NOT NULL";
            const string dropColmn    = "ALTER TABLE testtypes DROP COLUMN bytething";

            ExecuteSql(context, changeColumn);
            ExecuteSql(context, addColumn);
            ExecuteSql(context, dropColmn);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            var sb           = new StringBuilder();
            var modelDetails = ModelAnalyzer.GetModel <MsSqlTestTypesModel>();

            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                sb.Append("ALTER TABLE testtypes DROP COLUMN ").Append(property.PropertySourceName.ToLower()).Append(";\r\n");
            }
            var dropAllColumns = sb.ToString();

            ExecuteSql(context, dropAllColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);

            sb.Clear();
            foreach (var property in modelDetails.Properties)
            {
                if (property.IsIdentity || property.IsIdentityAutoGenerated || property.IsRelated)
                {
                    continue;
                }
                if (modelDetails.Properties.Any(x => x.ForeignIdentity == property.Name))
                {
                    continue;
                }
                if (property.IsNullable)
                {
                    sb.Append("ALTER TABLE testtypes ADD Junk").Append(property.PropertySourceName).Append(" ");
                    PostgreSql.PostgreSqlEngine.WriteSqlTypeFromModel(sb, property);
                    PostgreSql.PostgreSqlEngine.WriteTypeEndingFromModel(sb, property);
                    sb.Insert(sb.Length - 4, "NOT ");
                    sb.Append(";\r\n");
                }
            }
            var addJunkColumns = sb.ToString();

            ExecuteSql(context, addJunkColumns);

            _ = context.InitializeEngine <ITransactStoreEngine>(true);
        }