@databricks-solutions/lakebase-scm-utils 0.2.50 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scripts/index.cjs +2636 -2124
- package/dist/scripts/index.d.cts +1 -1
- package/dist/scripts/index.d.ts +1 -1
- package/dist/scripts/index.js +680 -178
- package/dist/scripts/lakebase/ci-resolve-branch.cli.cjs +2460 -2030
- package/dist/scripts/lakebase/ci-resolve-branch.cli.js +508 -81
- package/dist/scripts/lakebase/collapse-heads.cli.cjs +2429 -2007
- package/dist/scripts/lakebase/collapse-heads.cli.js +477 -58
- package/dist/scripts/lakebase/detect-language.cli.cjs +2441 -2016
- package/dist/scripts/lakebase/detect-language.cli.js +489 -67
- package/dist/scripts/lakebase/doctor.cli.cjs +2484 -2040
- package/dist/scripts/lakebase/doctor.cli.js +532 -91
- package/dist/scripts/lakebase/get-connection.cli.cjs +2 -2
- package/dist/scripts/lakebase/get-connection.cli.js +2 -2
- package/dist/scripts/lakebase/index.cjs +2633 -2121
- package/dist/scripts/lakebase/index.d.cts +59 -10
- package/dist/scripts/lakebase/index.d.ts +59 -10
- package/dist/scripts/lakebase/index.js +674 -172
- package/dist/scripts/lakebase/infra-runner.cli.cjs +2435 -2013
- package/dist/scripts/lakebase/infra-runner.cli.js +483 -64
- package/dist/scripts/lakebase/new-migration.cli.cjs +2429 -2007
- package/dist/scripts/lakebase/new-migration.cli.js +477 -58
- package/dist/scripts/lakebase/schema-diff.cli.cjs +2 -2
- package/dist/scripts/lakebase/schema-diff.cli.js +2 -2
- package/dist/scripts/lakebase/schema-migrate.cli.cjs +2461 -2029
- package/dist/scripts/lakebase/schema-migrate.cli.js +509 -80
- package/dist/scripts/lakebase/scm-claim-feature.cli.cjs +2460 -2030
- package/dist/scripts/lakebase/scm-claim-feature.cli.js +508 -81
- package/dist/scripts/lakebase/scm-doctor.cli.cjs +2486 -2056
- package/dist/scripts/lakebase/scm-doctor.cli.js +537 -107
- package/dist/scripts/lakebase/scm-merge.cli.cjs +2443 -2021
- package/dist/scripts/lakebase/scm-merge.cli.js +494 -72
- package/dist/scripts/lakebase/scm-reconcile-tier.cli.cjs +2464 -2034
- package/dist/scripts/lakebase/scm-reconcile-tier.cli.js +511 -84
- package/dist/scripts/util/index.cjs +2 -2
- package/dist/scripts/util/index.js +2 -2
- package/package.json +1 -1
- package/scripts/lakebase/adapters/efcore-adapter.ts +158 -0
- package/scripts/lakebase/adapters/flyway-adapter.ts +8 -5
- package/scripts/lakebase/collapse-heads.cli.ts +1 -1
- package/scripts/lakebase/create-project.ts +14 -12
- package/scripts/lakebase/detect-language.cli.ts +2 -2
- package/scripts/lakebase/doctor.ts +29 -0
- package/scripts/lakebase/dotnet-project.ts +112 -0
- package/scripts/lakebase/index.ts +1 -0
- package/scripts/lakebase/migration-layout.ts +43 -2
- package/scripts/lakebase/new-migration.cli.ts +1 -1
- package/scripts/lakebase/scaffold-language.ts +23 -2
- package/scripts/lakebase/scaffold.ts +4 -1
- package/scripts/lakebase/schema-migrate-runners/efcore.ts +399 -0
- package/scripts/lakebase/schema-migrate-runners/flyway.ts +6 -4
- package/scripts/lakebase/schema-migrate.cli.ts +3 -1
- package/scripts/lakebase/schema-migrate.ts +24 -10
- package/templates/project/common/.github/workflows/merge.yml +13 -1
- package/templates/project/common/.github/workflows/pr.yml +25 -5
- package/templates/project/common/.gitignore.base +7 -0
- package/templates/project/common/scripts/flyway-migrate.sh +54 -1
- package/templates/project/common/scripts/prepare-schema-diff.sh +5 -0
- package/templates/project/common/scripts/run-dev.sh +10 -1
- package/templates/project/common/scripts/run-tests.sh +6 -1
- package/templates/project/dotnet/.gitignore.extra +8 -0
- package/templates/project/dotnet/App.sln +56 -0
- package/templates/project/dotnet/Makefile +13 -0
- package/templates/project/dotnet/global.json +6 -0
- package/templates/project/dotnet/src/App/Data/AppDbContext.cs +12 -0
- package/templates/project/dotnet/src/App/Lakebase/DotEnv.cs +48 -0
- package/templates/project/dotnet/src/App/Lakebase/LakebaseConnection.cs +225 -0
- package/templates/project/dotnet/src/App/Program.cs +34 -0
- package/templates/project/dotnet/src/App/appsettings.json +9 -0
- package/templates/project/dotnet/tests/App.Tests/App.Tests.csproj +25 -0
- package/templates/project/dotnet/tests/App.Tests/HealthTests.cs +18 -0
- package/templates/project/dotnet/tests/App.Tests/OpenApiTests.cs +23 -0
- package/templates/project/dotnet-efcore/.config/dotnet-tools.json +13 -0
- package/templates/project/dotnet-efcore/src/App/App.csproj +22 -0
- package/templates/project/dotnet-efcore/src/App/Data/DesignTimeDbContextFactory.cs +24 -0
- package/templates/project/dotnet-efcore/src/App/Migrations/README.md +23 -0
- package/templates/project/dotnet-flyway/db/migrations/README.md +23 -0
- package/templates/project/dotnet-flyway/src/App/App.csproj +17 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
using System.Net;
|
|
2
|
+
using System.Net.Http.Json;
|
|
3
|
+
using Microsoft.AspNetCore.Mvc.Testing;
|
|
4
|
+
|
|
5
|
+
namespace App.Tests;
|
|
6
|
+
|
|
7
|
+
public class HealthTests(WebApplicationFactory<Program> factory) : IClassFixture<WebApplicationFactory<Program>>
|
|
8
|
+
{
|
|
9
|
+
[Fact]
|
|
10
|
+
public async Task Health_ReturnsOk()
|
|
11
|
+
{
|
|
12
|
+
var response = await factory.CreateClient().GetAsync("/health");
|
|
13
|
+
|
|
14
|
+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
15
|
+
var body = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>();
|
|
16
|
+
Assert.Equal("ok", body!["status"]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
using System.Net;
|
|
2
|
+
using Microsoft.AspNetCore.Mvc.Testing;
|
|
3
|
+
|
|
4
|
+
namespace App.Tests;
|
|
5
|
+
|
|
6
|
+
public class OpenApiTests(WebApplicationFactory<Program> factory) : IClassFixture<WebApplicationFactory<Program>>
|
|
7
|
+
{
|
|
8
|
+
[Fact]
|
|
9
|
+
public async Task OpenApiDocument_ListsEndpoints()
|
|
10
|
+
{
|
|
11
|
+
var body = await factory.CreateClient().GetStringAsync("/openapi.json");
|
|
12
|
+
|
|
13
|
+
Assert.Contains("\"/health\"", body);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[Fact]
|
|
17
|
+
public async Task Docs_ServesSwaggerUi()
|
|
18
|
+
{
|
|
19
|
+
var response = await factory.CreateClient().GetAsync("/docs/index.html");
|
|
20
|
+
|
|
21
|
+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<Nullable>enable</Nullable>
|
|
6
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
7
|
+
<RootNamespace>App</RootNamespace>
|
|
8
|
+
<!-- {{PROJECT_NAME}} -->
|
|
9
|
+
</PropertyGroup>
|
|
10
|
+
|
|
11
|
+
<ItemGroup>
|
|
12
|
+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
|
13
|
+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.12" />
|
|
14
|
+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.3.0" />
|
|
15
|
+
<!-- Marks this project as the EF Core migrations owner for lakebase-schema-migrate. -->
|
|
16
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.4">
|
|
17
|
+
<PrivateAssets>all</PrivateAssets>
|
|
18
|
+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
19
|
+
</PackageReference>
|
|
20
|
+
</ItemGroup>
|
|
21
|
+
|
|
22
|
+
</Project>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
using App.Lakebase;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Microsoft.EntityFrameworkCore.Design;
|
|
4
|
+
|
|
5
|
+
namespace App.Data;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Used by `dotnet ef` (and the kit's lakebase-schema-migrate) to build the
|
|
9
|
+
/// DbContext without starting the web host. It reads the same connection
|
|
10
|
+
/// settings as the app: DATABASE_URL when set (the kit passes the target
|
|
11
|
+
/// branch DSN this way, so no password appears on a command line), otherwise
|
|
12
|
+
/// the Lakebase metadata in .env with a runtime-minted credential.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
|
15
|
+
{
|
|
16
|
+
public AppDbContext CreateDbContext(string[] args)
|
|
17
|
+
{
|
|
18
|
+
DotEnv.LoadFromRepoRoot();
|
|
19
|
+
var options = new DbContextOptionsBuilder<AppDbContext>()
|
|
20
|
+
.UseNpgsql(LakebaseConnection.CreateDataSource())
|
|
21
|
+
.Options;
|
|
22
|
+
return new AppDbContext(options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# EF Core migrations
|
|
2
|
+
|
|
3
|
+
Create a migration with the kit's tool-agnostic command (run in the project
|
|
4
|
+
root):
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
./scripts/lk lakebase-new-migration --name "<description>"
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This runs `dotnet ef migrations add`, which generates the migration from the
|
|
11
|
+
difference between your `AppDbContext` model and the last snapshot. Review the
|
|
12
|
+
generated `Up()` / `Down()` before committing. You can also run
|
|
13
|
+
`dotnet ef migrations add <Name> --project src/App` directly.
|
|
14
|
+
|
|
15
|
+
EF Core names migrations `<UTC timestamp>_<Name>.cs`, so sibling feature
|
|
16
|
+
branches never collide on an id. Commit the migration, its `.Designer.cs`, and
|
|
17
|
+
the updated `AppDbContextModelSnapshot.cs` together.
|
|
18
|
+
|
|
19
|
+
You do not run migrations by hand: the kit applies them to each paired Lakebase
|
|
20
|
+
branch through CI (`pr.yml` on the feature branch, `merge.yml` on staging /
|
|
21
|
+
production) via `lakebase-schema-migrate`, which passes the branch connection to
|
|
22
|
+
`dotnet ef` in `DATABASE_URL` (read by `Data/DesignTimeDbContextFactory.cs`).
|
|
23
|
+
To migrate your paired branch locally, run `./scripts/flyway-migrate.sh`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Flyway migrations
|
|
2
|
+
|
|
3
|
+
Create a migration with the kit's tool-agnostic command (run in the project
|
|
4
|
+
root):
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
./scripts/lk lakebase-new-migration --name "<description>"
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
This writes a timestamp-versioned skeleton (`V<timestamp>__<slug>.sql`, a UTC
|
|
11
|
+
`YYYYMMDDHHMMSS` version); then author the DDL/DML. Timestamps are globally
|
|
12
|
+
unique and sort chronologically, so sibling feature branches never collide on a
|
|
13
|
+
version. Flyway runs with `-baselineOnMigrate=true -baselineVersion=0`, so every
|
|
14
|
+
`V<n>` file is applied as a pending migration.
|
|
15
|
+
|
|
16
|
+
Flyway owns the schema; EF Core is used only as the runtime ORM. Keep your
|
|
17
|
+
`AppDbContext` model in step with the SQL here, and do not add EF Core
|
|
18
|
+
migrations to this project.
|
|
19
|
+
|
|
20
|
+
You do not run migrations by hand: the kit applies them to each paired Lakebase
|
|
21
|
+
branch through CI (`pr.yml` on the feature branch, `merge.yml` on staging /
|
|
22
|
+
production) via `lakebase-schema-migrate`. To migrate your paired branch
|
|
23
|
+
locally, run `./scripts/flyway-migrate.sh`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<Nullable>enable</Nullable>
|
|
6
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
7
|
+
<RootNamespace>App</RootNamespace>
|
|
8
|
+
<!-- {{PROJECT_NAME}} -->
|
|
9
|
+
</PropertyGroup>
|
|
10
|
+
|
|
11
|
+
<ItemGroup>
|
|
12
|
+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
|
13
|
+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.12" />
|
|
14
|
+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.3.0" />
|
|
15
|
+
</ItemGroup>
|
|
16
|
+
|
|
17
|
+
</Project>
|