public void derive_the_function_signature_from_the_body() { var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody); func.Signature().ShouldBe("public.mt_upsert_target(jsonb, character varying, uuid, uuid)"); }
public void do_substitutions() { var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody); func.BuildTemplate($"*{DdlRules.SCHEMA}*").ShouldBe("*public*"); func.BuildTemplate($"*{DdlRules.FUNCTION}*").ShouldBe("*mt_upsert_target*"); func.BuildTemplate($"*{DdlRules.SIGNATURE}*").ShouldBe($"*{func.Signature()}*"); }
public SchemaObjects(Type documentType, TableDefinition table, ActualIndex[] actualIndices, FunctionBody function) { DocumentType = documentType; Table = table; Function = function; actualIndices.Each(x => ActualIndices.Add(x.Name, x)); }
private FunctionDiff createFunctionDiff(IDocumentSchema schema) { var actual = schema.DbObjects.DefinitionForFunction(_function); var expectedBody = SchemaBuilder.GetSqlScript(schema.StoreOptions.DatabaseSchemaName, _function.Name); var expected = new FunctionBody(_function, new string[] { _dropSql }, expectedBody); return(new FunctionDiff(expected, actual)); }
private FunctionDiff createFunctionDiff(IDocumentSchema schema) { var actual = schema.DbObjects.DefinitionForFunction(_function); var expectedBody = SchemaBuilder.GetSqlScript(schema.StoreOptions.DatabaseSchemaName, _function.Name); var expected = new FunctionBody(_function, new string[] { _dropSql }, expectedBody); return new FunctionDiff(expected, actual); }
// TODO -- Really need to add some QueryHandlers for all this stuff to eliminate the duplication public SchemaObjects FindSchemaObjects(DocumentMapping mapping) { using (var connection = new ManagedConnection(_factory)) { return(connection.Execute(cmd => { cmd.CommandText = SchemaObjectsSQL; cmd.AddParameter("schema", mapping.Table.Schema); cmd.AddParameter("table_name", mapping.Table.Name); cmd.AddParameter("function", mapping.UpsertFunction.Name); cmd.AddParameter("qualified_name", mapping.Table.OwnerName); var reader = cmd.ExecuteReader(); var columns = new List <TableColumn>(); while (reader.Read()) { var column = new TableColumn(reader.GetString(0), reader.GetString(1)); columns.Add(column); } var pks = new List <string>(); reader.NextResult(); while (reader.Read()) { pks.Add(reader.GetString(0)); } reader.NextResult(); var upsertDefinition = reader.Read() ? reader.GetString(0) : null; var indices = new List <ActualIndex>(); reader.NextResult(); while (reader.Read()) { var index = new ActualIndex(mapping.Table, reader.GetString(3), reader.GetString(4)); indices.Add(index); } var table = columns.Any() ? new TableDefinition(mapping.Table, pks.FirstOrDefault(), columns) : null; reader.NextResult(); var drops = new List <string>(); while (reader.Read()) { drops.Add(reader.GetString(0)); } FunctionBody functionBody = upsertDefinition.IsEmpty() ? null : new FunctionBody(mapping.UpsertFunction, drops.ToArray(), upsertDefinition); return new SchemaObjects(mapping.DocumentType, table, indices.ToArray(), functionBody); })); } }
public SchemaObjects(Type documentType, TableDefinition table, ActualIndex[] actualIndices, FunctionBody function) { DocumentType = documentType; Table = table; Function = function; actualIndices.Each(x => ActualIndices.Add(x.Name, x)); }
public void WriteSchemaObjects(IDocumentSchema schema, StringWriter writer) { writer.WriteLine(GenerateFunction()); if (schema.StoreOptions.OwnerName.IsNotEmpty()) { writer.WriteLine(); var expected = new FunctionBody(Function, new string[] { ToDropSignature() }, GenerateFunction()); writer.WriteLine(expected.ToOwnershipCommand(schema.StoreOptions.OwnerName)); } }
public void write_patch_with_designated_owner() { var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody); var patch = new SchemaPatch(); var options = new StoreOptions { OwnerName = "bill" }; var diff = new FunctionDiff(func, null); diff.WritePatch(options, patch); patch.UpdateDDL.ShouldContain("ALTER FUNCTION public.mt_upsert_target(jsonb, character varying, uuid, uuid) OWNER TO \"bill\";"); }
public void write_patch_without_designated_owner() { var func = new FunctionBody(new FunctionName("public", "mt_upsert_target"), new string[0], theFunctionBody); var patch = new SchemaPatch(); var options = new StoreOptions {OwnerName = null}; var diff = new FunctionDiff(func, null); diff.WritePatch(options, patch); patch.UpdateDDL.ShouldNotContain("OWNER TO"); }
public void does_not_regenerate_the_function_if_it_exists() { var schema = Substitute.For<IDocumentSchema>(); var dbobjects = Substitute.For<IDbObjects>(); schema.DbObjects.Returns(dbobjects); var func = TransformFunction.ForFile(new StoreOptions(), _getFullnameJs); var body = new FunctionBody(func.Function, new string[0], func.GenerateFunction()); dbobjects.DefinitionForFunction(func.Function).Returns(body); var patch = new SchemaPatch(new DdlRules()); func.GenerateSchemaObjectsIfNecessary(AutoCreate.All, schema, patch); var generated = func.GenerateFunction(); patch.UpdateDDL.ShouldNotContain(generated); patch.RollbackDDL.ShouldNotContain(func.Function.QualifiedName); }
private FunctionDiff functionDiff(IDocumentSchema schema) { var body = schema.DbObjects.DefinitionForFunction(Function); var expected = new FunctionBody(Function, new string[] {ToDropSignature()}, GenerateFunction()); return new FunctionDiff(expected, body); }
public FunctionDiff(FunctionBody expected, FunctionBody actual) { Expected = expected; Actual = actual; }
public FunctionDiff(FunctionBody expected, FunctionBody actual) { Expected = expected; Actual = actual; }