-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data): Cria script a partir da Migration
Utiliza-se o comando 'dotnet ef migrations script -p <projeto.csprog> -o <arquivo.sql>' para exportar a migration em um script SQL
- Loading branch information
1 parent
084a4a2
commit bb2aad9
Showing
1 changed file
with
117 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL | ||
BEGIN | ||
CREATE TABLE [__EFMigrationsHistory] ( | ||
[MigrationId] nvarchar(150) NOT NULL, | ||
[ProductVersion] nvarchar(32) NOT NULL, | ||
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) | ||
); | ||
END; | ||
GO | ||
|
||
BEGIN TRANSACTION; | ||
GO | ||
|
||
CREATE TABLE [Category] ( | ||
[Id] int NOT NULL IDENTITY, | ||
[Slug] VARCHAR(80) NOT NULL, | ||
[Title] NVARCHAR(80) NOT NULL, | ||
CONSTRAINT [PK_Category] PRIMARY KEY ([Id]) | ||
); | ||
GO | ||
|
||
CREATE TABLE [Role] ( | ||
[Id] int NOT NULL IDENTITY, | ||
[Name] VARCHAR(80) NOT NULL, | ||
[Slug] VARCHAR(80) NOT NULL, | ||
CONSTRAINT [PK_Role] PRIMARY KEY ([Id]) | ||
); | ||
GO | ||
|
||
CREATE TABLE [Tag] ( | ||
[Id] int NOT NULL IDENTITY, | ||
[Name] VARCHAR(80) NOT NULL, | ||
[Slug] VARCHAR(80) NOT NULL, | ||
CONSTRAINT [PK_Tag] PRIMARY KEY ([Id]) | ||
); | ||
GO | ||
|
||
CREATE TABLE [User] ( | ||
[Id] int NOT NULL IDENTITY, | ||
[Bio] TEXT NOT NULL, | ||
[Email] VARCHAR(200) NOT NULL, | ||
[Image] VARCHAR(2000) NOT NULL, | ||
[Name] NVARCHAR(80) NOT NULL, | ||
[PasswordHash] VARCHAR(255) NOT NULL, | ||
[Slug] VARCHAR(80) NOT NULL, | ||
CONSTRAINT [PK_User] PRIMARY KEY ([Id]) | ||
); | ||
GO | ||
|
||
CREATE TABLE [Post] ( | ||
[Id] int NOT NULL IDENTITY, | ||
[AuthorId] int NOT NULL, | ||
[Body] TEXT NOT NULL, | ||
[CategoryId] int NOT NULL, | ||
[CreateDate] SMALLDATETIME NOT NULL DEFAULT (GETDATE()), | ||
[LastUpdateDate] SMALLDATETIME NOT NULL DEFAULT (GETDATE()), | ||
[Slug] VARCHAR(80) NOT NULL, | ||
[Summary] VARCHAR(255) NOT NULL, | ||
[Title] VARCHAR(160) NOT NULL, | ||
CONSTRAINT [PK_Post] PRIMARY KEY ([Id]), | ||
CONSTRAINT [FK_Post_Author] FOREIGN KEY ([AuthorId]) REFERENCES [User] ([Id]) ON DELETE CASCADE, | ||
CONSTRAINT [FK_Post_Category] FOREIGN KEY ([CategoryId]) REFERENCES [Category] ([Id]) ON DELETE CASCADE | ||
); | ||
GO | ||
|
||
CREATE TABLE [UserRole] ( | ||
[RoleId] int NOT NULL, | ||
[UserId] int NOT NULL, | ||
CONSTRAINT [PK_UserRole] PRIMARY KEY ([RoleId], [UserId]), | ||
CONSTRAINT [FK_UserRole_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [Role] ([Id]) ON DELETE CASCADE, | ||
CONSTRAINT [FK_UserRole_UserId] FOREIGN KEY ([UserId]) REFERENCES [User] ([Id]) ON DELETE CASCADE | ||
); | ||
GO | ||
|
||
CREATE TABLE [PostTag] ( | ||
[PostId] int NOT NULL, | ||
[TagId] int NOT NULL, | ||
CONSTRAINT [PK_PostTag] PRIMARY KEY ([PostId], [TagId]), | ||
CONSTRAINT [FK_PostTag_PostId] FOREIGN KEY ([PostId]) REFERENCES [Post] ([Id]) ON DELETE CASCADE, | ||
CONSTRAINT [FK_PostTag_TagId] FOREIGN KEY ([TagId]) REFERENCES [Tag] ([Id]) ON DELETE CASCADE | ||
); | ||
GO | ||
|
||
CREATE UNIQUE INDEX [IX_Category_Slug] ON [Category] ([Slug]); | ||
GO | ||
|
||
CREATE INDEX [IX_Post_AuthorId] ON [Post] ([AuthorId]); | ||
GO | ||
|
||
CREATE INDEX [IX_Post_CategoryId] ON [Post] ([CategoryId]); | ||
GO | ||
|
||
CREATE UNIQUE INDEX [IX_Post_Slug] ON [Post] ([Slug]); | ||
GO | ||
|
||
CREATE INDEX [IX_PostTag_TagId] ON [PostTag] ([TagId]); | ||
GO | ||
|
||
CREATE UNIQUE INDEX [IX_Role_Slug] ON [Role] ([Slug]); | ||
GO | ||
|
||
CREATE UNIQUE INDEX [IX_Tag_Slug] ON [Tag] ([Slug]); | ||
GO | ||
|
||
CREATE UNIQUE INDEX [IX_User_Slug] ON [User] ([Slug]); | ||
GO | ||
|
||
CREATE INDEX [IX_UserRole_UserId] ON [UserRole] ([UserId]); | ||
GO | ||
|
||
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) | ||
VALUES (N'20221108003635_InitialCreate', N'7.0.0'); | ||
GO | ||
|
||
COMMIT; | ||
GO | ||
|