-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgresql adapter #10
Closed
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1ec7c0f
Initial impl of postgresql adapter
mrahhal 6aea52a
Add postgresql initial migration
mrahhal 7896306
Clean, remove commented table hints
mrahhal bddaf87
Edit pg dev connection string
mrahhal 7bb2b3d
Merge branch 'master' into postgresql-adapter
mrahhal 2221669
Brackets to quotes
mrahhal 4a3d9d9
Merge branch 'master' into postgresql-adapter
mrahhal c56123e
Virtualize creating queries in timeout job
mrahhal 5f9fe16
React to timeout fetched job usage
mrahhal dd8635c
Quote everything
mrahhal 768e7d9
fix: delete expired entities query in postgres
mrahhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MR.AspNetCore.Jobs.Models; | ||
|
||
namespace MR.AspNetCore.Jobs | ||
{ | ||
public class JobsDbContextFactory : IDesignTimeDbContextFactory<JobsDbContext> | ||
{ | ||
internal static string DevConnectionString = | ||
Environment.GetEnvironmentVariable("MR_ASPNETCORE_JOBS_POSTGRESQL_CS_DEV") ?? | ||
@"Server=127.0.0.1;Port=5432;Database=MR.AspNetCore.Jobs.Dev;User Id=postgres;Password=password;"; | ||
|
||
public JobsDbContext CreateDbContext(string[] args) | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddSingleton(new PostgreSQLOptions()); | ||
services.AddDbContext<JobsDbContext>(opts => | ||
{ | ||
opts.UseNpgsql(DevConnectionString, sqlOpts => | ||
{ | ||
sqlOpts.MigrationsHistoryTable( | ||
EFCoreOptions.DefaultMigrationsHistoryTableName, | ||
EFCoreOptions.DefaultSchema); | ||
}); | ||
}); | ||
|
||
return services.BuildServiceProvider().GetRequiredService<JobsDbContext>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace MR.AspNetCore.Jobs | ||
{ | ||
internal static class LoggerExtensions | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/MR.AspNetCore.Jobs.PostgreSQL/MR.AspNetCore.Jobs.PostgreSQL.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="../../build/common.props" /> | ||
|
||
<PropertyGroup Label="Build"> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
<RootNamespace>MR.AspNetCore.Jobs</RootNamespace> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Label="Package"> | ||
<Description>A PostgreSQL adapter for MR.AspNetCore.Jobs.</Description> | ||
<PackageTags>aspnetcore;background;jobs;sql;postgresql;netstandard</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MR.AspNetCore.Jobs.EFCore\MR.AspNetCore.Jobs.EFCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
98 changes: 98 additions & 0 deletions
98
src/MR.AspNetCore.Jobs.PostgreSQL/Migrations/20171125160624_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
src/MR.AspNetCore.Jobs.PostgreSQL/Migrations/20171125160624_InitialCreate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MR.AspNetCore.Jobs.Migrations | ||
{ | ||
public partial class InitialCreate : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.EnsureSchema( | ||
name: "Jobs"); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "CronJobs", | ||
schema: "Jobs", | ||
columns: table => new | ||
{ | ||
Id = table.Column<string>(nullable: false), | ||
Cron = table.Column<string>(nullable: true), | ||
LastRun = table.Column<DateTime>(nullable: false), | ||
Name = table.Column<string>(nullable: false), | ||
TypeName = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_CronJobs", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Jobs", | ||
schema: "Jobs", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(nullable: false) | ||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), | ||
Added = table.Column<DateTime>(nullable: false), | ||
Data = table.Column<string>(nullable: true), | ||
Due = table.Column<DateTime>(nullable: true), | ||
ExpiresAt = table.Column<DateTime>(nullable: true), | ||
Retries = table.Column<int>(nullable: false), | ||
StateName = table.Column<string>(nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Jobs", x => x.Id); | ||
}); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "JobQueue", | ||
schema: "Jobs", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(nullable: false) | ||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), | ||
JobId = table.Column<int>(nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_JobQueue", x => x.Id); | ||
table.ForeignKey( | ||
name: "FK_JobQueue_Jobs_JobId", | ||
column: x => x.JobId, | ||
principalSchema: "Jobs", | ||
principalTable: "Jobs", | ||
principalColumn: "Id", | ||
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_CronJobs_Name", | ||
schema: "Jobs", | ||
table: "CronJobs", | ||
column: "Name", | ||
unique: true); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_JobQueue_JobId", | ||
schema: "Jobs", | ||
table: "JobQueue", | ||
column: "JobId"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Jobs_StateName", | ||
schema: "Jobs", | ||
table: "Jobs", | ||
column: "StateName"); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Jobs_Due_StateName", | ||
schema: "Jobs", | ||
table: "Jobs", | ||
columns: new[] { "Due", "StateName" }); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "CronJobs", | ||
schema: "Jobs"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "JobQueue", | ||
schema: "Jobs"); | ||
|
||
migrationBuilder.DropTable( | ||
name: "Jobs", | ||
schema: "Jobs"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this overrides what you configure as your connection string in your applications service configuration, so probably should remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm mistaken somehow, this is the connection string that will be used at design time while developing only (to run migrations). In your own app, this whole class should never be used. That's supposedly what
IDesignTimeDbContextFactory
does. Can you explain why you think this will override that in the app?