コード例 #1
0
ファイル: TenantSchema.cs プロジェクト: amferguson/marten
        public async Task WriteMigrationFileByTypeAsync(string directory)
        {
            var system = new FileSystem();

            system.DeleteDirectory(directory);
            system.CreateDirectory(directory);
            var features = _features.AllActiveFeatures(_tenant).ToArray();

            writeDatabaseSchemaGenerationScript(directory, system, features);

            using var conn = _tenant.CreateConnection();
            await conn.OpenAsync();

            foreach (var feature in features)
            {
                var migration = await SchemaMigration.Determine(conn, feature.Objects);

                if (migration.Difference == SchemaPatchDifference.None)
                {
                    continue;
                }

                var file = directory.AppendPath(feature.Identifier + ".sql");
                DdlRules.WriteTemplatedFile(file, (r, w) =>
                {
                    migration.WriteAllUpdates(w, r, AutoCreate.CreateOrUpdate);
                });
            }
        }
コード例 #2
0
        public async Task create_a_schema_on_the_fly_for_migrations()
        {
            await theConnection.OpenAsync();

            await theConnection.DropSchema("one");

            await theConnection.DropSchema("two");

            var table1 = new Table("one.table1");

            table1.AddColumn <string>("name").AsPrimaryKey();

            var table2 = new Table("two.table2");

            table2.AddColumn <string>("name").AsPrimaryKey();

            var migration = await SchemaMigration.Determine(theConnection, new ISchemaObject[] { table1, table2 });

            migration.Difference.ShouldBe(SchemaPatchDifference.Create);

            await migration.ApplyAll(theConnection, new DdlRules(), AutoCreate.CreateOrUpdate);

            (await table1.FetchExisting(theConnection)).ShouldNotBeNull();
            (await table2.FetchExisting(theConnection)).ShouldNotBeNull();
        }
コード例 #3
0
ファイル: TenantSchema.cs プロジェクト: amferguson/marten
        public async Task <SchemaMigration> CreateMigrationAsync()
        {
            var @objects = _features.AllActiveFeatures(_tenant).SelectMany(x => x.Objects).ToArray();

            using var conn = _tenant.CreateConnection();
            await conn.OpenAsync();

            return(await SchemaMigration.Determine(conn, @objects));
        }
コード例 #4
0
        private async Task writeAndApplyPatch(AutoCreate autoCreate, DocumentTable table)
        {
            var migration = await SchemaMigration.Determine(_conn, new ISchemaObject[] { table });


            if (migration.Difference != SchemaPatchDifference.None)
            {
                await migration.ApplyAll(_conn, new DdlRules(), autoCreate);
            }
        }
コード例 #5
0
ファイル: TenantSchema.cs プロジェクト: amferguson/marten
        public async Task <SchemaMigration> CreateMigrationAsync(Type documentType)
        {
            var mapping = _features.MappingFor(documentType);

            using var conn = _tenant.CreateConnection();
            await conn.OpenAsync();

            var migration = await SchemaMigration.Determine(conn, mapping.Schema.Objects);

            return(migration);
        }
コード例 #6
0
ファイル: ExtensionTests.cs プロジェクト: JasperFx/weasel
        public async Task can_create_extension()
        {
            await ResetSchema();

            var extension = new Extension("plv8");

            await DropSchemaObjectInDatabase(extension);


            var migration = await SchemaMigration.Determine(theConnection, extension);

            migration.Difference.ShouldBe(SchemaPatchDifference.Create);

            await this.CreateSchemaObjectInDatabase(extension);


            migration = await SchemaMigration.Determine(theConnection, extension);

            migration.Difference.ShouldBe(SchemaPatchDifference.None);
        }