Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
055bf94b
Commit
055bf94b
authored
Jul 17, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update batchsql scripts.
parent
a3d26ab7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
27 deletions
+14
-27
SqlServerStorage.cs
src/DotNetCore.CAP.EntityFrameworkCore/SqlServerStorage.cs
+14
-27
No files found.
src/DotNetCore.CAP.EntityFrameworkCore/SqlServerStorage.cs
View file @
055bf94b
...
@@ -4,52 +4,42 @@ using System.Threading;
...
@@ -4,52 +4,42 @@ using System.Threading;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Dapper
;
using
Dapper
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
namespace
DotNetCore.CAP.EntityFrameworkCore
namespace
DotNetCore.CAP.EntityFrameworkCore
{
{
public
class
SqlServerStorage
:
IStorage
public
class
SqlServerStorage
:
IStorage
{
{
private
readonly
IServiceProvider
_provider
;
private
readonly
SqlServerOptions
_options
;
private
readonly
ILogger
_logger
;
private
readonly
ILogger
_logger
;
public
SqlServerStorage
(
public
SqlServerStorage
(
ILogger
<
SqlServerStorage
>
logger
,
SqlServerOptions
options
)
IServiceProvider
provider
,
ILogger
<
SqlServerStorage
>
logger
)
{
{
_
provider
=
provider
;
_
options
=
options
;
_logger
=
logger
;
_logger
=
logger
;
}
}
public
async
Task
InitializeAsync
(
CancellationToken
cancellationToken
)
public
async
Task
InitializeAsync
(
CancellationToken
cancellationToken
)
{
using
(
var
scope
=
_provider
.
CreateScope
())
{
{
if
(
cancellationToken
.
IsCancellationRequested
)
return
;
if
(
cancellationToken
.
IsCancellationRequested
)
return
;
var
provider
=
scope
.
ServiceProvider
;
var
sql
=
CreateDbTablesScript
(
_options
.
Schema
);
var
options
=
provider
.
GetRequiredService
<
SqlServerOptions
>();
var
sql
=
CreateDbTablesScript
(
options
.
Schema
);
using
(
var
connection
=
new
SqlConnection
(
options
.
ConnectionString
))
using
(
var
connection
=
new
SqlConnection
(
_
options
.
ConnectionString
))
{
{
await
connection
.
ExecuteAsync
(
sql
);
await
connection
.
ExecuteAsync
(
sql
);
}
}
_logger
.
LogDebug
(
"Ensuring all create database tables script are applied."
);
_logger
.
LogDebug
(
"Ensuring all create database tables script are applied."
);
}
}
}
protected
virtual
string
CreateDbTablesScript
(
string
schema
)
protected
virtual
string
CreateDbTablesScript
(
string
schema
)
{
{
var
batchSql
=
var
batchSql
=
$@"
$@"
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '
{
schema
}
')
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '
{
schema
}
')
BEGIN
BEGIN
EXEC('CREATE SCHEMA
{
schema
}
')
EXEC('CREATE SCHEMA
{
schema
}
')
END
END;
GO
IF OBJECT_ID(N'[
{
schema
}
].[Queue]',N'U') IS NULL
IF OBJECT_ID(N'[
{
schema
}
].[Queue]',N'U') IS NULL
BEGIN
BEGIN
...
@@ -57,8 +47,7 @@ BEGIN
...
@@ -57,8 +47,7 @@ BEGIN
[MessageId] [int] NOT NULL,
[MessageId] [int] NOT NULL,
[MessageType] [tinyint] NOT NULL
[MessageType] [tinyint] NOT NULL
) ON [PRIMARY]
) ON [PRIMARY]
END
END;
GO
IF OBJECT_ID(N'[
{
schema
}
].[Received]',N'U') IS NULL
IF OBJECT_ID(N'[
{
schema
}
].[Received]',N'U') IS NULL
BEGIN
BEGIN
...
@@ -76,8 +65,7 @@ CREATE TABLE [{schema}].[Received](
...
@@ -76,8 +65,7 @@ CREATE TABLE [{schema}].[Received](
[Id] ASC
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
END;
GO
IF OBJECT_ID(N'[
{
schema
}
].[Published]',N'U') IS NULL
IF OBJECT_ID(N'[
{
schema
}
].[Published]',N'U') IS NULL
BEGIN
BEGIN
...
@@ -94,8 +82,7 @@ CREATE TABLE [{schema}].[Published](
...
@@ -94,8 +82,7 @@ CREATE TABLE [{schema}].[Published](
[Id] ASC
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
END;"
;
GO"
;
return
batchSql
;
return
batchSql
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment