Skip to content

Commit

Permalink
## 5.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
vbilopav committed Aug 1, 2023
1 parent 9d37ad7 commit a20c387
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 18 deletions.
69 changes: 58 additions & 11 deletions PgRoutiner/Builder/Dump/DumpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ string GetDir(DumpType type)
var baseSequencesDir = GetDir(DumpType.Sequences);
var baseExtensionsDir = GetDir(DumpType.Extensions);

int tableCount = 0;
int viewsCount = 0;
int functionsCount = 0;
int proceduresCount = 0;
int domainsCount = 0;
int typesCount = 0;
int schemasCount = 0;
int sequencesCount = 0;
int extensionsCount = 0;

/*
static string ParseSchema(string dir, string schema)
{
if (dir == null)
Expand All @@ -110,7 +121,7 @@ static string ParseSchema(string dir, string schema)
}
return string.Format(dir, schema == null || schema == "public" ? "" : schema).Replace("//", "/").Replace("\\\\", "\\");
}

*/

HashSet<string> dirs = new();

Expand All @@ -120,17 +131,33 @@ static string ParseSchema(string dir, string schema)
{
continue;
}
var schemaDir = string.Concat(schema == null || schema == "public" ? "" : schema, "/");

var dir = type switch
{
PgType.Table => ParseSchema(baseTablesDir, schema),
PgType.View => ParseSchema(baseViewsDir, schema),
PgType.Function => ParseSchema(baseFunctionsDir, schema),
PgType.Procedure => ParseSchema(baseProceduresDir, schema),
PgType.Domain => ParseSchema(baseDomainsDir, schema),
PgType.Type => ParseSchema(baseTypesDir, schema),
PgType.Schema => ParseSchema(baseSchemasDir, schema),
PgType.Sequence => ParseSchema(baseSequencesDir, schema),
PgType.Extension => ParseSchema(baseExtensionsDir, schema),
PgType.Table => baseTablesDir, //ParseSchema(baseTablesDir, schema),
PgType.View => baseViewsDir, //ParseSchema(baseViewsDir, schema),
PgType.Function => baseFunctionsDir, //ParseSchema(baseFunctionsDir, schema),
PgType.Procedure => baseProceduresDir, //ParseSchema(baseProceduresDir, schema),
PgType.Domain => baseDomainsDir, //ParseSchema(baseDomainsDir, schema),
PgType.Type => baseTypesDir, //ParseSchema(baseTypesDir, schema),
PgType.Schema => baseSchemasDir, //ParseSchema(baseSchemasDir, schema),
PgType.Sequence => baseSequencesDir, //ParseSchema(baseSequencesDir, schema),
PgType.Extension => baseExtensionsDir, //ParseSchema(baseExtensionsDir, schema),
_ => null
};

int? count = type switch
{
PgType.Table => ++tableCount,
PgType.View => ++viewsCount,
PgType.Function => ++functionsCount,
PgType.Procedure => ++proceduresCount,
PgType.Domain => ++domainsCount,
PgType.Type => ++typesCount,
PgType.Schema => ++schemasCount,
PgType.Sequence => ++sequencesCount,
PgType.Extension => ++extensionsCount,
_ => null
};

Expand Down Expand Up @@ -160,7 +187,25 @@ static string ParseSchema(string dir, string schema)
}
}

var file = string.Format(Path.GetFullPath(Path.Combine(dir, shortFilename)), connectionName);
var shortName = $"{schemaDir}{shortFilename}";
var file = Path.GetFullPath(dir.FormatByName(
("0", shortName),
("file", shortName),
("fileName", shortName),
("1", schema),
("schema", schema),
("2", objectName),
("name", objectName),
("3", connectionName),
("connection", connectionName),
("4", count),
("count", count),
("number", count)))
.Replace("//", "/")
.Replace("\\\\", "\\")
.SanitazePath();

dir = Path.GetDirectoryName(file);
var relative = file.GetRelativePath();

if (!dirs.Contains(dir.TrimEnd('/').TrimEnd('\\')))
Expand Down Expand Up @@ -234,6 +279,7 @@ private static void CreateDir(string dir, bool skipDelete = false)
}
}

/*
private static void RemoveDir(string dir)
{
if (!Current.Value.DumpConsole)
Expand All @@ -253,4 +299,5 @@ private static void RemoveDir(string dir)
Directory.Delete(dir, true);
}
}
*/
}
4 changes: 2 additions & 2 deletions PgRoutiner/Builder/Md/MarkdownDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void BuildViews(StringBuilder content, StringBuilder header, List<string
}
//var viewsHeader = false;
var viewComments = connection.GetViewComments(settings, schema).ToList();
var count = viewComments.Count();
var count = viewComments.GroupBy(t => t.Table).Count();
if (count > 0)
{
header.AppendLine();
Expand Down Expand Up @@ -480,7 +480,7 @@ void WriteStats(string schema, string table)
Dictionary<string, string> additionalColumnComments = new();
var tableComments = connection.GetTableComments(settings, schema).ToList();

var count = tableComments.Count();
var count = tableComments.GroupBy(t => t.Table).Count();
if (count > 0)
{
header.AppendLine();
Expand Down
9 changes: 7 additions & 2 deletions PgRoutiner/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static string GetFrom(this string value)
}
index1 = index1 + seq.Length;
var index2 = 0;
for(var i = index1; i < value.Length; i++)
for (var i = index1; i < value.Length; i++)
{
var ch = value[i];
if (ch.IsSqlChar())
Expand Down Expand Up @@ -382,4 +382,9 @@ public static string GetAssumedNamespace(this Current settings)
}
return ns;
}
}

public static string FormatByName(this string input, params (string key, object value)[] parameters)
{
return parameters.Aggregate(input, (current, parameter) => current.Replace(string.Concat("{", parameter.key, "}"), parameter.value?.ToString() ?? ""));
}
}
6 changes: 3 additions & 3 deletions PgRoutiner/PgRoutiner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<PackageProjectUrl Condition="'$(Configuration)'!='SelfContained'">https://github.com/vb-consulting/PgRoutiner</PackageProjectUrl>
<PackageTags Condition="'$(Configuration)'!='SelfContained'">PostgreSQL</PackageTags>
<GeneratePackageOnBuild Condition="'$(Configuration)'!='SelfContained'">true</GeneratePackageOnBuild>
<Version>5.3.5.0</Version>
<Version>5.3.6.0</Version>
<PackageId Condition="'$(Configuration)'!='SelfContained'">dotnet-pgroutiner</PackageId>
<AssemblyVersion>5.3.5.0</AssemblyVersion>
<FileVersion>5.3.5.0</FileVersion>
<AssemblyVersion>5.3.6.0</AssemblyVersion>
<FileVersion>5.3.6.0</FileVersion>
<Configurations>Debug;Release;SelfContained</Configurations>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
Expand Down
38 changes: 38 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
# VERSION HISTORY

## 5.3.6

### Fix wrong counts in TOC of markdown document.

### Improve `DbObjects` section name handling.

Now, dir names can accept named formats (instead of just numbers). This applies to `DbObjectsDir`˙and all `DbObjectsDirNames` (`Tables`, `Views`, `Enums`, `Sequences`, `Functions`, `Procedures`, `Extensions`).

Available named formats are:

- "0" - constructed file name: `subdir/schema_name_object_name.sql` where sibdir is schema name if not public, otherwise it's empty (base dir). This is for compatibility with previous versions.
- "file" - same.
- "fileName" - same.
- "1" - schema name.
- "schema" - same.
- "2" - object name.
- "name" - same.
- "3" - connection name
- "connection" - same.
- "4" - object count number (for this type).
- "count" - same.
- "number" - same.

This feature is added to support flyway migrations name format for repeatable migrations.

For example, if we have `DbObjectsDirNames` set to `{"Functions": "R__F_{count}_{schema}.{name}.sql"}` then we will have following directory files:

- `/R__F_1_public.func1.sql`
- `/R__F_1_public.func2.sql`

This repeatable flyway migration format.

Default name settings are the same as before.

```
```json
## 5.3.5
- Massive improvements to markdown documentation generation.
Expand Down

0 comments on commit a20c387

Please sign in to comment.