From f658f13f7d642f0eaad2173bca1e9cf73672fa07 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 29 Jan 2024 17:01:55 +1000 Subject: [PATCH] Copied from main project --- src/Sample/Program.cs | 73 +++++++++ src/Sample/Sample.csproj | 15 ++ src/Sample/Scripts/Script0001_sqlite.sql | 141 +++++++++++++++++ src/Sample/Scripts/Script0002_sqlite.sql | 169 +++++++++++++++++++++ src/Sample/Scripts/Script0003_sqlite.sql | 31 ++++ src/Sample/Scripts/Script0004_sqlite.sql | 8 + src/Tests/DatabaseSupportTests.cs | 3 +- src/Tests/NoPublicApiChanges.cs | 2 +- src/Tests/SQLiteSupportTests.cs | 5 +- src/Tests/SQLiteTableJournalTests.cs | 4 +- src/Tests/Tests.csproj | 7 +- src/dbup-sqlite/Properties/AssemblyInfo.cs | 12 -- src/dbup-sqlite/dbup-sqlite.csproj | 26 ++-- src/dbup-sqllite.sln | 6 + 14 files changed, 471 insertions(+), 31 deletions(-) create mode 100644 src/Sample/Program.cs create mode 100644 src/Sample/Sample.csproj create mode 100644 src/Sample/Scripts/Script0001_sqlite.sql create mode 100644 src/Sample/Scripts/Script0002_sqlite.sql create mode 100644 src/Sample/Scripts/Script0003_sqlite.sql create mode 100644 src/Sample/Scripts/Script0004_sqlite.sql diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs new file mode 100644 index 0000000..daa406c --- /dev/null +++ b/src/Sample/Program.cs @@ -0,0 +1,73 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using DbUp; +using DbUp.Engine; +using DbUp.SQLite.Helpers; + +namespace SQLiteSampleApplication +{ + class Program + { + static void Main() + { + using (var database = new TemporarySQLiteDatabase("test")) + { + database.Create(); + + var upgrader = + DeployChanges.To + .SQLiteDatabase(database.SharedConnection) + .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) + .LogToConsole() + .Build(); + + var watch = new Stopwatch(); + watch.Start(); + + var result = upgrader.PerformUpgrade(); + + watch.Stop(); + Display("File", result, watch.Elapsed); + } // Database will be deleted at this point + + using (var database = new InMemorySQLiteDatabase()) + { + var upgrader = + DeployChanges.To + .SQLiteDatabase(database.ConnectionString) + .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) + .LogToConsole() + .Build(); + + var watch = new Stopwatch(); + watch.Start(); + + var result = upgrader.PerformUpgrade(); + + watch.Stop(); + Display("InMemory", result, watch.Elapsed); + } // Database will disappear from memory at this point + } + + static void Display(string dbType, DatabaseUpgradeResult result, TimeSpan ts) + { + // Display the result + if (result.Successful) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Success!"); + Console.WriteLine("{0} Database Upgrade Runtime: {1}", dbType, + string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)); + Console.ReadKey(); + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(result.Error); + Console.ReadKey(); + Console.WriteLine("Failed!"); + } + } + } +} diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj new file mode 100644 index 0000000..df2f803 --- /dev/null +++ b/src/Sample/Sample.csproj @@ -0,0 +1,15 @@ + + + net8.0 + Exe + false + + + + + + + + + + diff --git a/src/Sample/Scripts/Script0001_sqlite.sql b/src/Sample/Scripts/Script0001_sqlite.sql new file mode 100644 index 0000000..c9857fc --- /dev/null +++ b/src/Sample/Scripts/Script0001_sqlite.sql @@ -0,0 +1,141 @@ +--------------------------------------- +-- Script 0001 +-- Creates following tables: +-- * Entry +-- * Revision +-- * Comment +-- * Setting +-- * Redirect +-- * Pingback +-- * Tag +-- * TagItem +-- * TaskState +--------------------------------------- + +-- Entry Table +CREATE TABLE [Entry] +( + [Id] INTEGER CONSTRAINT 'PK_Entry_ID' PRIMARY KEY AUTOINCREMENT, + [Name] NVARCHAR(50) NOT NULL, + [Title] NVARCHAR(200) NOT NULL, + [Summary] TEXT NOT NULL, + [Published] DATETIME NOT NULL, + [LatestRevisionId] INT NULL, + [IsDiscussionEnabled] BIT NOT NULL CONSTRAINT[DF_Entry_IsDiscussionEnabled] DEFAULT(1), + [MetaDescription] NVARCHAR(500) NOT NULL CONSTRAINT[DF_Entry_MetaDescription] DEFAULT(''), + [MetaTitle] NVARCHAR(255) NOT NULL CONSTRAINT[DF_Entry_MetaTitle] DEFAULT(''), + [HideChrome] BIT NOT NULL CONSTRAINT[DF_Entry_HideChrome] DEFAULT(0), + [Status] NVARCHAR(20) NOT NULL CONSTRAINT [DF_Entry_Status] DEFAULT('Public-Page'), + [PageTemplate] NVARCHAR(20) NULL, + [Author] NVARCHAR(100) NOT NULL, + [RevisionAuthor] NVARCHAR(100) NOT NULL, + [LastRevised] DATETIME NOT NULL, + [LatestRevisionFormat] NVARCHAR(20) NOT NULL, + [TagsCommaSeparated] NVARCHAR(255) NOT NULL CONSTRAINT [DF_Entry_TagsCommaSeparated] DEFAULT(''), + [CommentCount] INT NOT NULL CONSTRAINT [DF_Entry_CommentCount] DEFAULT(0) +); + +-- Entry Revision Table +CREATE TABLE [Revision] +( + [Id] INTEGER CONSTRAINT 'PK_Revision_ID' PRIMARY KEY AUTOINCREMENT, + [EntryId] INT NOT NULL, + [Body] TEXT NOT NULL, + [Reason] NVARCHAR(1000) NOT NULL, + [Revised] DATETIME NOT NULL, + [Status] INT NOT NULL, + [RevisionNumber] INT NOT NULL CONSTRAINT[DF_Revision_RevisionNumber] DEFAULT 0, + [Format] NVARCHAR(20) NOT NULL CONSTRAINT[DF_Revision_Format] DEFAULT('Markdown'), + [Author] NVARCHAR(100) NOT NULL, + CONSTRAINT 'FK_Revision_EntryId' FOREIGN KEY (EntryId) REFERENCES Entry(Id) + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +-- Comment Table +CREATE TABLE [Comment] +( + [Id] INTEGER CONSTRAINT 'PK_Comment_ID' PRIMARY KEY AUTOINCREMENT, + [Body] TEXT NOT NULL, + [AuthorName] NVARCHAR(100) NOT NULL, + [AuthorEmail] NVARCHAR(100) NOT NULL, + [AuthorUrl] NVARCHAR(100) NOT NULL, + [Posted] DATETIME NOT NULL, + [EntryId] INT NOT NULL, + [Status] INT NOT NULL, + CONSTRAINT 'FK_Comment_EntryId' FOREIGN KEY (EntryId) REFERENCES Entry(Id) + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +-- Settings and Statistics Table +CREATE TABLE [Setting] +( + [Id] INTEGER CONSTRAINT 'PK_Setting_ID' PRIMARY KEY AUTOINCREMENT, + [Name] NVARCHAR(50) NOT NULL, + [Description] TEXT NOT NULL, + [DisplayName] NVARCHAR(200) NOT NULL, + [Value] TEXT NOT NULL +) +; + +-- Redirect Table +CREATE TABLE [Redirect] +( + [Id] INTEGER CONSTRAINT 'PK_Redirect_ID' PRIMARY KEY AUTOINCREMENT, + [From] NVARCHAR(255) NOT NULL, + [To] NVARCHAR(255) NOT NULL +) +; + +-- Pingback Table +CREATE TABLE [Pingback] +( + [Id] INTEGER CONSTRAINT 'PK_Pingback_ID' PRIMARY KEY AUTOINCREMENT, + [EntryId] INT NOT NULL, + [TargetUri] NVARCHAR(255) NOT NULL, + [TargetTitle] NVARCHAR(255) NOT NULL, + [IsSpam] BIT NOT NULL, + [Received] DATETIME NOT NULL, + CONSTRAINT 'FK_Pingback_EntryId' FOREIGN KEY (EntryId) REFERENCES Entry(Id) + ON UPDATE NO ACTION + ON DELETE NO ACTION +) +; + +-- Tag Table +CREATE TABLE [Tag] +( + [Id] INTEGER CONSTRAINT 'PK_Tag_ID' PRIMARY KEY AUTOINCREMENT, + [Name] NVARCHAR(50) NOT NULL +) +; + +-- TagItem Table +CREATE TABLE [TagItem] +( + [Id] INTEGER CONSTRAINT 'PK_TagItem_ID' PRIMARY KEY AUTOINCREMENT, + [EntryId] INT NOT NULL, + [TagId] INT NOT NULL, + CONSTRAINT 'FK_TagItem_EntryId' FOREIGN KEY (EntryId) REFERENCES Entry(Id) + ON UPDATE NO ACTION + ON DELETE NO ACTION, + CONSTRAINT 'FK_TagItem_TagId' FOREIGN KEY (TagId) REFERENCES Tag(Id) + ON UPDATE NO ACTION + ON DELETE NO ACTION +) +; + +-- TaskState Table (records the status of a long-running task) +CREATE TABLE [TaskState] +( + [Id] INTEGER CONSTRAINT 'PK_TaskState_ID' PRIMARY KEY AUTOINCREMENT, + [TaskName] NVARCHAR(50) NOT NULL, + [Arguments] TEXT NOT NULL, + [ProgressEstimate] INT, + [Status] NVARCHAR(30), + [OutputLog] TEXT NOT NULL, + [Started] DATETIME NOT NULL, + [Updated] DATETIME NOT NULL +) +; diff --git a/src/Sample/Scripts/Script0002_sqlite.sql b/src/Sample/Scripts/Script0002_sqlite.sql new file mode 100644 index 0000000..81f6939 --- /dev/null +++ b/src/Sample/Scripts/Script0002_sqlite.sql @@ -0,0 +1,169 @@ +--------------------------------------- +-- Script 0002 +-- Initializes Settings +--------------------------------------- + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'ui-title', + 'Title', + 'My FunnelWeb Site', + 'Text: The title shown at the top in the browser.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'ui-introduction', + 'Introduction', + 'Welcome to your FunnelWeb blog. You can login and edit this message in the administration section. The default username and password is test/test.', 'Markdown: The introductory text that is shown on the home page.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'ui-links', + 'Main Links', + '
  • Projects
  • ', 'HTML: A list of links shown at the top of each page.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'search-author', + 'Author', + 'Daffy Duck', + 'Text: Your name.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'search-keywords', + 'Keywords', + '.net, c#, test', + 'Comma-separated text: Keywords shown to search engines.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'search-description', + 'Description', + 'My website.', + 'Text: The description shown to search engines in the meta description tag.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'spam-blacklist', + 'Spam Blacklist', + 'casino', + 'Comments with these words (case-insensitive) will automatically be marked as spam, in addition to Akismet.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'default-page', + 'Default Page', + 'blog', + 'Page name: When users visit the root (/) of your site, it will be equivalent to visiting the page you specify here.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'ui-footer', + 'Footer', + '

    Powered by FunnelWeb, the blog engine of real developers.

    ', 'HTML: This will appear at the bottom of the page - use it to add copyright information, links to any web hosts, people or technologies that helped you to build the site, and so on.'); +; + +INSERT INTO [Setting] + ([Id], + [Name], + [DisplayName], + [Value], + [Description]) +VALUES + (Null, + 'ui-theme', + 'Theme', + 'Clean', + 'Theme being used by the blog at the moment'); +; + +INSERT INTO [Setting]( + [Name], + [DisplayName], + [Value], + [Description] +) +VALUES ( + 'enable-disqus-comments', + 'Enable Disque Comments', + 'False', + 'Enable the Disqus commenting system. Note - this will still require the theme to also use Disqus.' +); + +INSERT INTO [Setting]( + [Id], + [Name], + [DisplayName], + [Value], + [Description] +) +VALUES ( + Null, + 'disqus-shortname', + 'Shortname for Disqus', + '', + 'The shortname of your Disqus comments, configured on the Disqus website.' +); diff --git a/src/Sample/Scripts/Script0003_sqlite.sql b/src/Sample/Scripts/Script0003_sqlite.sql new file mode 100644 index 0000000..64a6bb5 --- /dev/null +++ b/src/Sample/Scripts/Script0003_sqlite.sql @@ -0,0 +1,31 @@ +--------------------------------------- +-- Script 0003 +-- Creates Sql Authentication Tables +--------------------------------------- + +-- User Table +CREATE TABLE [User] ( + [Id] INTEGER CONSTRAINT 'PK_User_ID' PRIMARY KEY AUTOINCREMENT, + [Name] NVARCHAR(100) NOT NULL, + [Username] NVARCHAR(50) NOT NULL, + [Password] NVARCHAR(50) NOT NULL, + [Email] NVARCHAR(50) NOT NULL +) +; + +-- Role Table +CREATE TABLE [Role] ( + [Id] INTEGER CONSTRAINT 'PK_Role_ID' PRIMARY KEY AUTOINCREMENT, + [Name] NVARCHAR(50) NOT NULL +) +; + +-- User Roles Table +CREATE TABLE [UserRoles] ( + [UserId] INT NOT NULL, + [RoleId] INT NOT NULL, + CONSTRAINT 'FK_UserRoles_ID' PRIMARY KEY (UserId, RoleId), + CONSTRAINT 'FK_UserRoles_UserId' FOREIGN KEY (UserId) REFERENCES User(Id), + CONSTRAINT 'FK_UserRoles_RoleId' FOREIGN KEY (RoleId) REFERENCES Role(Id) +) +; diff --git a/src/Sample/Scripts/Script0004_sqlite.sql b/src/Sample/Scripts/Script0004_sqlite.sql new file mode 100644 index 0000000..ddd0bef --- /dev/null +++ b/src/Sample/Scripts/Script0004_sqlite.sql @@ -0,0 +1,8 @@ +--------------------------------------- +-- Script 0004 +-- Initializes Roles +--------------------------------------- + +INSERT INTO [Role] (Name) VALUES ('Admin'); +INSERT INTO [Role] (Name) VALUES ('Moderator'); + diff --git a/src/Tests/DatabaseSupportTests.cs b/src/Tests/DatabaseSupportTests.cs index 18584e1..6fd3237 100644 --- a/src/Tests/DatabaseSupportTests.cs +++ b/src/Tests/DatabaseSupportTests.cs @@ -1,8 +1,7 @@ using DbUp.Builder; -using DbUp.SQLite; using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.SQLite; +namespace DbUp.SQLite.Tests; public class DatabaseSupportTests : DatabaseSupportTestsBase { diff --git a/src/Tests/NoPublicApiChanges.cs b/src/Tests/NoPublicApiChanges.cs index 06c0966..81e81d9 100644 --- a/src/Tests/NoPublicApiChanges.cs +++ b/src/Tests/NoPublicApiChanges.cs @@ -1,6 +1,6 @@ using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.SQLite; +namespace DbUp.SQLite.Tests; public class NoPublicApiChanges : NoPublicApiChangesBase { diff --git a/src/Tests/SQLiteSupportTests.cs b/src/Tests/SQLiteSupportTests.cs index d961a6c..bd0d553 100644 --- a/src/Tests/SQLiteSupportTests.cs +++ b/src/Tests/SQLiteSupportTests.cs @@ -2,10 +2,9 @@ using System; using System.Data.SQLite; using System.IO; -using NUnit.Framework; using Xunit; -namespace DbUp.Tests.Support.SQLite +namespace DbUp.SQLite.Tests { public class SQLiteSupportTests { @@ -28,4 +27,4 @@ public void CanUseSQLite() } } } -#endif \ No newline at end of file +#endif diff --git a/src/Tests/SQLiteTableJournalTests.cs b/src/Tests/SQLiteTableJournalTests.cs index 6f404a4..ce0171a 100644 --- a/src/Tests/SQLiteTableJournalTests.cs +++ b/src/Tests/SQLiteTableJournalTests.cs @@ -5,14 +5,12 @@ using DbUp.Engine; using DbUp.Engine.Output; using DbUp.Engine.Transactions; -using DbUp.SQLite; using DbUp.Tests.Common; -using DbUp.Tests.TestInfrastructure; using NSubstitute; using Shouldly; using Xunit; -namespace DbUp.Tests.Support.SQLite +namespace DbUp.SQLite.Tests { public class SQLiteTableJournalTests { diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 9090010..3a39421 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -8,15 +8,20 @@ enable + + $(DefineConstants);NETCORE + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/dbup-sqlite/Properties/AssemblyInfo.cs b/src/dbup-sqlite/Properties/AssemblyInfo.cs index 2848f04..e0cd465 100644 --- a/src/dbup-sqlite/Properties/AssemblyInfo.cs +++ b/src/dbup-sqlite/Properties/AssemblyInfo.cs @@ -1,18 +1,6 @@ using System; -using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("dbup_sqlite")] -[assembly: AssemblyTrademark("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] [assembly: CLSCompliant(true)] diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index 089c94e..da35aad 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -3,31 +3,39 @@ DbUp makes it easy to deploy and upgrade SQL Server databases. This package adds SQLite support. DbUp SQLite Support + DbUp Contributors + DbUp + Copyright © DbUp Contributors 2015 netstandard1.3;net462 + dbup-sqlite + DbUp.SQLite + dbup-sqlite ../dbup.snk true - true - false - false - false + https://github.com/DbUp/dbup-sqlite.git + dbup-icon.png + + + + $(DefineConstants);NETCORE - + - - $(DefineConstants);NETCORE - - + + + + diff --git a/src/dbup-sqllite.sln b/src/dbup-sqllite.sln index 868f847..213e0f9 100644 --- a/src/dbup-sqllite.sln +++ b/src/dbup-sqllite.sln @@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{77157734-01D dbup-sqlite.sln.DotSettings = dbup-sqlite.sln.DotSettings EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{E3BA8B01-82D8-44C3-BE55-F9E08DE53D26}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {8CE634FE-6772-408E-9340-909F6218F8F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {8CE634FE-6772-408E-9340-909F6218F8F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {8CE634FE-6772-408E-9340-909F6218F8F7}.Release|Any CPU.Build.0 = Release|Any CPU + {E3BA8B01-82D8-44C3-BE55-F9E08DE53D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3BA8B01-82D8-44C3-BE55-F9E08DE53D26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3BA8B01-82D8-44C3-BE55-F9E08DE53D26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3BA8B01-82D8-44C3-BE55-F9E08DE53D26}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {62E5FE92-E288-4E09-964D-F92AF0E49131} = {5DA19CA9-8039-46D6-B474-021943582785}