├── Build.bat ├── License.txt ├── packages ├── NUnit.2.6.0.12054 │ ├── tools │ │ ├── runpnunit.bat │ │ ├── agent.conf │ │ ├── nunit.exe │ │ ├── lib │ │ │ ├── fit.dll │ │ │ ├── Failure.png │ │ │ ├── Ignored.png │ │ │ ├── Skipped.png │ │ │ ├── Success.png │ │ │ ├── log4net.dll │ │ │ ├── nunit.core.dll │ │ │ ├── nunit.uikit.dll │ │ │ ├── nunit.util.dll │ │ │ ├── Inconclusive.png │ │ │ ├── nunit-gui-runner.dll │ │ │ ├── nunit.fixtures.dll │ │ │ ├── nunit.uiexception.dll │ │ │ ├── nunit-console-runner.dll │ │ │ └── nunit.core.interfaces.dll │ │ ├── runFile.exe │ │ ├── nunit-x86.exe │ │ ├── nunit-agent.exe │ │ ├── pnunit-agent.exe │ │ ├── pnunit.tests.dll │ │ ├── nunit-agent-x86.exe │ │ ├── nunit-console.exe │ │ ├── nunit.framework.dll │ │ ├── pnunit-launcher.exe │ │ ├── nunit-console-x86.exe │ │ ├── pnunit.framework.dll │ │ ├── agent.log.conf │ │ ├── launcher.log.conf │ │ ├── NUnitTests.nunit │ │ ├── test.conf │ │ ├── runFile.exe.config │ │ ├── nunit-console.exe.config │ │ ├── nunit-agent.exe.config │ │ ├── nunit-console-x86.exe.config │ │ ├── nunit-agent-x86.exe.config │ │ ├── pnunit-agent.exe.config │ │ ├── pnunit-launcher.exe.config │ │ ├── nunit.exe.config │ │ ├── nunit-x86.exe.config │ │ └── NUnitTests.config │ ├── license.txt │ └── lib │ │ └── nunit.framework.dll ├── Moq.4.0.10827 │ ├── Moq.chm │ ├── lib │ │ ├── NET35 │ │ │ ├── Moq.dll │ │ │ └── Moq.pdb │ │ ├── NET40 │ │ │ ├── Moq.dll │ │ │ └── Moq.pdb │ │ └── Silverlight4 │ │ │ ├── Castle.Core.dll │ │ │ ├── Moq.Silverlight.dll │ │ │ └── Moq.Silverlight.pdb │ └── License.txt └── repositories.config ├── Build.ps1 ├── .editorconfig ├── Insight.Database.Schema ├── GlobalSuppressions.cs ├── packages.config ├── SchemaEventType.cs ├── SchemaEventConsoleLogger.cs ├── Implementation │ ├── Script.cs │ ├── Contract.cs │ ├── Service.cs │ ├── BrokerPriority.cs │ ├── Role.cs │ ├── User.cs │ ├── Function.cs │ ├── View.cs │ ├── Table.cs │ ├── StoredProcedure.cs │ ├── Certificate.cs │ ├── Trigger.cs │ ├── SymmetricKey.cs │ ├── MasterKey.cs │ ├── Constraint.cs │ ├── Schema.cs │ ├── MessageType.cs │ ├── Login.cs │ ├── Queue.cs │ ├── PartitionFunction.cs │ ├── UserDefinedType.cs │ ├── Index.cs │ ├── PartitionScheme.cs │ ├── PrimaryKey.cs │ ├── Default.cs │ ├── AutoProc.cs │ ├── Permission.cs │ └── SchemaImpl.cs ├── IColumnDefinitionProvider.cs ├── CodeAnalysisRules.ruleset ├── SchemaRegistryEntry.cs ├── Properties │ └── AssemblyInfo.cs ├── ColumnDefinition.cs ├── SchemaEventArgs.cs ├── LambdaComparer.cs ├── SchemaException.cs ├── SchemaParsingException.cs ├── ConnectionExtensions.cs ├── Singularizer.cs ├── SqlName.cs ├── SchemaEventLogger.cs ├── RecordingDbCommand.cs ├── SqlColumnDefinitionProvider.cs └── SchemaObjectType.cs ├── .hgignore ├── Insight.Database.Schema.Sample ├── app.config ├── Receipts.sql ├── Sizes.sql ├── Glasses.sql ├── Servings.sql ├── Beer.sql ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── Insight.Database.Schema.Sample.csproj ├── Insight.Database.Schema.Tests ├── packages.config ├── SingularizerTests.cs ├── Properties │ └── AssemblyInfo.cs ├── DatabaseTests.cs ├── BaseInstallerTest.cs ├── SqlParserTests.cs └── Insight.Database.Schema.Tests.csproj ├── .gitignore ├── Insight.Database.Schema.Installer ├── App.config ├── Properties │ └── AssemblyInfo.cs └── Insight.Database.Schema.Installer.csproj ├── Insight.Database.Schema.Verifier ├── App.config ├── Properties │ └── AssemblyInfo.cs └── Insight.Database.Schema.Verifier.csproj ├── Properties ├── Settings.settings ├── AssemblyInfo.cs ├── Settings.Designer.cs ├── Resources.Designer.cs └── Resources.resx ├── Building.txt ├── Insight.Database.Schema.nuspec ├── .hgtags ├── Build.psake.ps1 ├── README.md ├── TestSchema.sql ├── autobuild.proj └── Insight.sln /Build.bat: -------------------------------------------------------------------------------- 1 | PowerShell .\build.ps1 %1 -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/License.txt -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/runpnunit.bat: -------------------------------------------------------------------------------- 1 | start pnunit-agent agent.conf 2 | pnunit-launcher test.conf -------------------------------------------------------------------------------- /Build.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string] $target = "default" 3 | ) 4 | 5 | Invoke-psake .\Build.psake.ps1 -taskList $target 6 | -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/Moq.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/Moq.chm -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/license.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/license.txt -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/NET35/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/NET35/Moq.dll -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/NET35/Moq.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/NET35/Moq.pdb -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/NET40/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/NET40/Moq.dll -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/NET40/Moq.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/NET40/Moq.pdb -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/agent.conf: -------------------------------------------------------------------------------- 1 | 2 | 8080 3 | . 4 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit.exe -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = crlf 3 | insert_final_newline = true 4 | indent_style = tab 5 | indent_size = 4 6 | trim_tailing_whitespace = true -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/fit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/fit.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/runFile.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/runFile.exe -------------------------------------------------------------------------------- /Insight.Database.Schema/GlobalSuppressions.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/Insight.Database.Schema/GlobalSuppressions.cs -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit-x86.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/Failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/Failure.png -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/Ignored.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/Ignored.png -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/Skipped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/Skipped.png -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/Success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/Success.png -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/log4net.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-agent.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit-agent.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit-agent.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/pnunit-agent.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit.tests.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/pnunit.tests.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/lib/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/lib/nunit.framework.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.core.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.uikit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.uikit.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.util.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.util.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-agent-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit-agent-x86.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-console.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit-console.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit.framework.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit-launcher.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/pnunit-launcher.exe -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | glob:bin 2 | glob:obj 3 | glob:*.user 4 | glob:*.suo 5 | syntax: glob 6 | *.docstates 7 | *.nupkg 8 | *.orig 9 | *.rej 10 | StyleCop.Cache 11 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/Inconclusive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/Inconclusive.png -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-console-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/nunit-console-x86.exe -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/pnunit.framework.dll -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit-gui-runner.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit-gui-runner.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.fixtures.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.fixtures.dll -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.pdb -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.uiexception.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.uiexception.dll -------------------------------------------------------------------------------- /Insight.Database.Schema/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit-console-runner.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit-console-runner.dll -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/lib/nunit.core.interfaces.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fg/Insight.Database.Schema/master/packages/NUnit.2.6.0.12054/tools/lib/nunit.core.interfaces.dll -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.user 4 | *.suo 5 | *.docstates 6 | *.nupkg 7 | *.orig 8 | *.rej 9 | StyleCop.Cache 10 | 11 | TestResult.xml 12 | 13 | Insight.Database.Schema.Tests.dll.config 14 | packages -------------------------------------------------------------------------------- /Insight.Database.Schema.Installer/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Verifier/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Receipts.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Receipts] 2 | ( 3 | [ID] [int] NOT NULL, 4 | [Name] [nvarchar](128) NOT NULL 5 | ) ON [PRIMARY] 6 | GO 7 | 8 | ALTER TABLE [Receipts] WITH NOCHECK ADD CONSTRAINT [PK_Receipts] PRIMARY KEY NONCLUSTERED 9 | ( 10 | [ID] 11 | ) 12 | GO 13 | 14 | -- AUTOPROC All [Receipts] 15 | GO -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Sizes.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Sizes] 2 | ( 3 | [BeerID] [int] NOT NULL, 4 | [GlassID] [int] NOT NULL, 5 | ) ON [PRIMARY] 6 | GO 7 | 8 | ALTER TABLE [Sizes] WITH NOCHECK ADD CONSTRAINT [PK_Sizes] PRIMARY KEY NONCLUSTERED 9 | ( 10 | [BeerID], 11 | [GlassID] 12 | ) 13 | GO 14 | 15 | -- AUTOPROC All [Sizes] 16 | GO -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Glasses.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Glasses] 2 | ( 3 | [ID] [int] IDENTITY, 4 | [Name] [varchar](32) NULL, 5 | [Ounces] [int] NULL 6 | ) ON [PRIMARY] 7 | GO 8 | 9 | ALTER TABLE [Glasses] WITH NOCHECK ADD CONSTRAINT [PK_Glasses] PRIMARY KEY NONCLUSTERED 10 | ( 11 | [ID] 12 | ) 13 | GO 14 | 15 | -- AUTOPROC All [Glasses] 16 | GO 17 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Servings.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Servings] 2 | ( 3 | [ID] [int] IDENTITY, 4 | [BeerID] [int] NOT NULL, 5 | [GlassesID] [int] NOT NULL, 6 | [When] [datetime] NULL, 7 | ) ON [PRIMARY] 8 | GO 9 | 10 | ALTER TABLE [Servings] WITH NOCHECK ADD CONSTRAINT [PK_Servings] PRIMARY KEY NONCLUSTERED 11 | ( 12 | [ID] 13 | ) 14 | GO 15 | 16 | -- AUTOPROC All [Servings] 17 | GO -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaEventType.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | #endregion 8 | 9 | namespace Insight.Database.Schema 10 | { 11 | /// 12 | /// The type of schema event 13 | /// 14 | public enum SchemaEventType 15 | { 16 | BeforeDrop, 17 | BeforeCreate, 18 | AfterCreate, 19 | DropFailed 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaEventConsoleLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Insight.Database.Schema 7 | { 8 | /// 9 | /// Logs console events to the console 10 | /// 11 | public class SchemaEventConsoleLogger : SchemaEventLogger 12 | { 13 | public override void LogSchemaChange (SchemaEventArgs se) 14 | { 15 | Console.WriteLine (FormatEventArgs (se)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Building.txt: -------------------------------------------------------------------------------- 1 | Notes for Building Insight.Database.Schema 2 | ========================================== 3 | 4 | * Build requires Psake. You can get it from http://nuget.org/packages/Psake 5 | * You will need to provide your own Insight.Database.Schema.Tests.dll.config file with your test connection strings. Try this one: 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Beer.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [Beer] 2 | ( 3 | [ID] [int] IDENTITY, 4 | [Name] [nvarchar](128) NOT NULL, 5 | [Flavor] [nvarchar](128) NULL, 6 | [OriginalGravity] [decimal](18, 2) NULL, 7 | [Details] [varchar](MAX), 8 | [Hoppiness] [int] DEFAULT(6), 9 | [Yumminess] AS [Hoppiness] * 2, 10 | [RowVersion] [timestamp] 11 | ) ON [PRIMARY] 12 | GO 13 | 14 | ALTER TABLE [Beer] WITH NOCHECK ADD CONSTRAINT [PK_Beer] PRIMARY KEY NONCLUSTERED 15 | ( 16 | [ID] 17 | ) 18 | GO 19 | 20 | -- AUTOPROC All,Optimistic [Beer] 21 | GO 22 | 23 | GRANT ALL ON SelectBeer TO [public] 24 | GO -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/agent.log.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/launcher.log.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Script.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Script : SchemaImpl 11 | { 12 | public Script(string name, string sql) : base(name, sql, 1) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return true; 19 | } 20 | 21 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 22 | { 23 | return false; 24 | } 25 | 26 | public override void Drop(IDbConnection connection) 27 | { 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/NUnitTests.nunit: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Insight.Database.Schema/IColumnDefinitionProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Insight.Database.Schema 7 | { 8 | /// 9 | /// Provides the schema engine the definitions of the columns of a table. 10 | /// 11 | /// This class is framework code and is not intended to be used by external code. 12 | public interface IColumnDefinitionProvider 13 | { 14 | /// 15 | /// Returns the column definitions for a given table. 16 | /// 17 | /// The name of the table. 18 | /// A list of the columns for the table. 19 | IList GetColumns(SqlName tableName); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Contract.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Contract : SchemaImpl 11 | { 12 | public Contract(string name, string sql) : base(name, sql, 1) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.service_contracts 21 | WHERE name = '{0}'", 22 | Name.Object)); 23 | } 24 | 25 | public override void Drop(IDbConnection connection) 26 | { 27 | connection.ExecuteSql(String.Format(@"DROP CONTRACT {0}", Name.ObjectFormatted)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Service.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Service : SchemaImpl 12 | { 13 | public Service(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.services 22 | WHERE name = '{0}'", 23 | Name.Object)); 24 | } 25 | 26 | public override void Drop(IDbConnection connection) 27 | { 28 | connection.ExecuteSql(String.Format(@"DROP SERVICE {0}", Name.ObjectFormatted)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/BrokerPriority.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class BrokerPriority : SchemaImpl 11 | { 12 | public BrokerPriority(string name, string sql) : base(name, sql, 1) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.conversation_priorities 21 | WHERE name = '{0}'", 22 | Name.Object)); 23 | } 24 | 25 | public override void Drop(IDbConnection connection) 26 | { 27 | connection.ExecuteSql(String.Format(@"DROP BROKER PRIORITY {0}", Name.ObjectFormatted)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Role.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Role : SchemaImpl 12 | { 13 | public Role(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.database_principals WHERE name = '{0}' AND type = 'R'", 22 | Name.Object)); 23 | } 24 | 25 | public override void Drop(IDbConnection connection) 26 | { 27 | connection.ExecuteSql(String.Format(@"DROP ROLE {0}", Name.ObjectFormatted)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class User : SchemaImpl 12 | { 13 | public User(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.database_principals WHERE name = '{0}' AND type <> 'R'", 22 | Name.Object)); 23 | } 24 | 25 | public override void Drop(IDbConnection connection) 26 | { 27 | connection.ExecuteSql(String.Format(@"DROP USER {0}", Name.ObjectFormatted)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Insight.Database.Schema/CodeAnalysisRules.ruleset: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/test.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Testing 6 | 7 | 8 | Testing 9 | pnunit.tests.dll 10 | TestLibraries.Testing.EqualTo19 11 | localhost:8080 12 | 13 | ..\server 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Function : SchemaImpl 11 | { 12 | public Function(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.objects o 21 | JOIN sys.schemas s ON (o.schema_id = s.schema_id) 22 | WHERE s.name = '{0}' AND o.name = '{1}'", 23 | Name.Schema, 24 | Name.Object)); 25 | } 26 | 27 | public override void Drop(IDbConnection connection) 28 | { 29 | connection.ExecuteSql(String.Format(@"DROP FUNCTION {0}", Name.SchemaQualifiedObject)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/View.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class View : SchemaImpl 11 | { 12 | public View(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(System.Data.IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.views v 21 | JOIN sys.schemas s ON (v.schema_id = s.schema_id) 22 | WHERE s.name = '{0}' AND v.name = '{1}'", 23 | Name.Schema, 24 | Name.Table)); 25 | } 26 | 27 | public override void Drop(System.Data.IDbConnection connection) 28 | { 29 | connection.ExecuteSql(String.Format ("DROP VIEW {0}", Name.FullName)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Table.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Table : SchemaImpl 11 | { 12 | public Table(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(System.Data.IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.tables t 21 | JOIN sys.schemas s ON (t.schema_id = s.schema_id) 22 | WHERE s.name = '{0}' AND t.name = '{1}'", 23 | Name.Schema, 24 | Name.Table)); 25 | } 26 | 27 | public override void Drop(System.Data.IDbConnection connection) 28 | { 29 | connection.ExecuteSql(String.Format ("DROP TABLE {0}", Name.FullName)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/StoredProcedure.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class StoredProcedure : SchemaImpl 11 | { 12 | public StoredProcedure(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.procedures p 21 | JOIN sys.schemas s ON (p.schema_id = s.schema_id) 22 | WHERE s.name = '{0}' AND p.name = '{1}'", 23 | Name.Schema, 24 | Name.Object)); 25 | } 26 | 27 | public override void Drop(IDbConnection connection) 28 | { 29 | connection.ExecuteSql(String.Format(@"DROP PROCEDURE {0}", 30 | Name.SchemaQualifiedObject)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaRegistryEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Insight.Database.Schema 7 | { 8 | /// 9 | /// Represents a record in the schema registry. 10 | /// 11 | class SchemaRegistryEntry 12 | { 13 | /// 14 | /// The schema group to which this belongs. 15 | /// 16 | public string SchemaGroup; 17 | 18 | /// 19 | /// The name of the schema object. 20 | /// 21 | public string ObjectName; 22 | 23 | /// 24 | /// The signature of the object. 25 | /// 26 | public string Signature; 27 | 28 | /// 29 | /// The type of the object. 30 | /// 31 | public SchemaObjectType Type; 32 | 33 | /// 34 | /// The original order in which the object was installed. 35 | /// 36 | public int OriginalOrder; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Certificate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Certificate : SchemaImpl 11 | { 12 | public Certificate(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.certificates 21 | WHERE name = '{0}'", 22 | Name.Object)); 23 | } 24 | 25 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 26 | { 27 | return false; 28 | } 29 | 30 | public override void Drop(IDbConnection connection) 31 | { 32 | throw new InvalidOperationException("For your protection, certificates must be dropped manually."); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.235 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | using System.Runtime.CompilerServices; 14 | using System.Runtime.InteropServices; 15 | 16 | [assembly: AssemblyTitle("eMoney Insight")] 17 | [assembly: AssemblyCompany("Insight Module")] 18 | [assembly: AssemblyProduct("Insight")] 19 | [assembly: AssemblyCopyright("Copyright © Jon Wagner, used by permission")] 20 | [assembly: ComVisible(false)] 21 | [assembly: CLSCompliant(false)] 22 | [assembly: AssemblyVersion("1.0.12.34")] 23 | [assembly: AssemblyFileVersion("1.0.12.34")] 24 | 25 | 26 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Trigger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Trigger : SchemaImpl 11 | { 12 | public Trigger(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override bool Exists(System.Data.IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.triggers t 21 | JOIN sys.objects o ON (t.object_id = o.object_id) 22 | JOIN sys.schemas s ON (o.schema_id = s.schema_id) 23 | WHERE s.name = '{0}' AND t.name = '{1}'", 24 | Name.Schema, 25 | Name.Table)); 26 | } 27 | 28 | public override void Drop(System.Data.IDbConnection connection) 29 | { 30 | connection.ExecuteSql(String.Format ("DROP TRIGGER {0}", Name.FullName)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/SingularizerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Moq; 7 | using NUnit.Framework; 8 | 9 | namespace Insight.Database.Schema.Tests 10 | { 11 | [TestFixture] 12 | public class SingularizerTests 13 | { 14 | private void Test(string plural, string singular) 15 | { 16 | Assert.AreEqual(plural.ToLower(), Singularizer.Singularize(singular).ToLower()); 17 | } 18 | 19 | #region Singular Tests 20 | [Test] 21 | public void TestSinglePlural() 22 | { 23 | Test("person", "people"); 24 | Test("octopus", "octopi"); 25 | Test("deer", "deer"); 26 | Test("wolf", "wolves"); 27 | Test("wife", "wives"); 28 | Test("compass", "compasses"); 29 | Test("cliff", "cliffs"); 30 | Test("turf", "turfs"); 31 | Test("case", "cases"); 32 | Test("objective", "objectives"); 33 | Test("size", "sizes"); 34 | } 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/SymmetricKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class SymmetricKey : SchemaImpl 12 | { 13 | public SymmetricKey(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(System.Data.IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.symmetric_keys 22 | WHERE name = '{0}'", 23 | Name.Object)); 24 | } 25 | 26 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 27 | { 28 | return false; 29 | } 30 | 31 | public override void Drop(System.Data.IDbConnection connection) 32 | { 33 | throw new InvalidOperationException("For your protection, symmetric keys must be dropped manually."); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/MasterKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class MasterKey : SchemaImpl 12 | { 13 | public MasterKey(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(System.Data.IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.symmetric_keys 22 | WHERE name = '{0}'", 23 | "##MS_DatabaseMasterKey##")); 24 | } 25 | 26 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 27 | { 28 | return false; 29 | } 30 | 31 | public override void Drop(System.Data.IDbConnection connection) 32 | { 33 | throw new InvalidOperationException("For your protection, master keys must be dropped manually."); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Constraint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Constraint : SchemaImpl 11 | { 12 | public Constraint(string name, string sql) : base(name, sql, 3) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@"SELECT COUNT(*) 19 | FROM sys.objects o 20 | JOIN sys.tables t ON (o.parent_object_id = t.object_id) 21 | JOIN sys.schemas s ON (t.schema_id = s.schema_id) 22 | WHERE s.Name = '{0}' AND t.name = '{1}' AND o.name = '{2}'", 23 | Name.Schema, 24 | Name.Table, 25 | Name.Object)); 26 | } 27 | 28 | public override void Drop(IDbConnection connection) 29 | { 30 | connection.ExecuteSql(String.Format(@"ALTER TABLE {0} DROP CONSTRAINT {1}", 31 | Name.SchemaQualifiedTable, 32 | Name.ObjectFormatted)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Schema.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Schema : SchemaImpl 12 | { 13 | public Schema(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(System.Data.IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format("SELECT COUNT (*) FROM sys.schemas WHERE name = '{0}'", Name.Object)); 20 | } 21 | 22 | public override void Drop(System.Data.IDbConnection connection) 23 | { 24 | connection.ExecuteSql(String.Format ("DROP SCHEMA {0}", Name.ObjectFormatted)); 25 | } 26 | 27 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 28 | { 29 | return 0 == connection.ExecuteScalarSql(String.Format("SELECT COUNT(*) FROM sys.objects o WHERE o.schema_id = SCHEMA_ID('{0}')", Name.Object)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.1 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Insight.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.235 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | using System.Runtime.CompilerServices; 14 | using System.Runtime.InteropServices; 15 | using System.Diagnostics.CodeAnalysis; 16 | using System.Resources; 17 | 18 | [assembly: AssemblyTitle("Insight.Database Schema")] 19 | [assembly: AssemblyCompany("Insight")] 20 | [assembly: AssemblyProduct("Insight")] 21 | [assembly: AssemblyCopyright("Copyright © Jon Wagner, used by permission")] 22 | [assembly: ComVisible(false)] 23 | [assembly: CLSCompliant(true)] 24 | [assembly: AssemblyVersion("1.0.0.0")] 25 | [assembly: AssemblyFileVersion("1.0.0.0")] 26 | 27 | [assembly: NeutralResourcesLanguageAttribute("en-US")] 28 | 29 | [assembly: InternalsVisibleTo("Insight.Database.Schema.Tests")] 30 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/MessageType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class MessageType : SchemaImpl 11 | { 12 | public MessageType(string name, string sql) : base(name, sql, 1) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@" 19 | SELECT COUNT (*) 20 | FROM sys.service_message_types 21 | WHERE name = '{0}'", 22 | Name.Object)); 23 | } 24 | 25 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 26 | { 27 | return 0 == connection.ExecuteScalarSql(String.Format(@" 28 | SELECT COUNT(*) 29 | FROM sys.service_contract_message_usages c 30 | JOIN sys.service_message_types m ON (c.message_type_id = m.message_type_id) 31 | WHERE m.name = '{0}'", 32 | Name.Object)); 33 | } 34 | 35 | public override void Drop(IDbConnection connection) 36 | { 37 | connection.ExecuteSql(String.Format(@"DROP MESSAGE TYPE {0}", Name.ObjectFormatted)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Login.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Login : SchemaImpl 12 | { 13 | public Login(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.server_principals WHERE name = '{0}' AND type <> 'R'", 22 | Name.Object)); 23 | } 24 | 25 | public override void Install(IDbConnection connection, IEnumerable objects) 26 | { 27 | if (!Exists(connection)) 28 | base.Install(connection, objects); 29 | } 30 | 31 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 32 | { 33 | // assume that logins can be used across the server 34 | return false; 35 | } 36 | 37 | public override void Drop(IDbConnection connection) 38 | { 39 | connection.ExecuteSql(String.Format(@"DROP LOGIN {0}", Name.ObjectFormatted)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Queue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Queue : SchemaImpl 12 | { 13 | public Queue(string name, string sql) : base(name, sql, 2) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.service_queues 22 | WHERE object_id = OBJECT_ID('{0}')", 23 | Name.SchemaQualifiedObject)); 24 | } 25 | 26 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 27 | { 28 | return 0 == connection.ExecuteScalarSql(String.Format(@" 29 | SELECT COUNT(*) 30 | FROM sys.service_queues q 31 | JOIN sys.service_queue_usages u ON (q.object_id = u.service_queue_id) 32 | WHERE q.object_id = OBJECT_ID('{0}')", 33 | Name.SchemaQualifiedObject)); 34 | } 35 | 36 | public override void Drop(IDbConnection connection) 37 | { 38 | connection.ExecuteSql(String.Format(@"DROP QUEUE {0}", Name.SchemaQualifiedObject)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/PartitionFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class PartitionFunction : SchemaImpl 12 | { 13 | public PartitionFunction(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.partition_functions 22 | WHERE name = '{0}'", 23 | Name.Object)); 24 | } 25 | 26 | public override bool CanModify(SchemaInstaller.InstallContext context, IDbConnection connection) 27 | { 28 | // we can drop a function as long as there are no schemes using it 29 | return connection.ExecuteScalarSql( 30 | "SELECT COUNT(*) FROM sys.partition_functions p JOIN sys.partition_schemes s ON (p.function_id = s.function_id) WHERE p.name = @Name", 31 | new Dictionary() { { "Name", Name.Object } }) == 0; 32 | } 33 | 34 | public override void Drop(IDbConnection connection) 35 | { 36 | connection.ExecuteSql(String.Format(@"DROP PARTITION FUNCTION {0}", Name.ObjectFormatted)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/UserDefinedType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class UserDefinedType : SchemaImpl 12 | { 13 | public UserDefinedType(string name, string sql) : base(name, sql, 2) 14 | { 15 | } 16 | 17 | public override bool Exists(System.Data.IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.types t 22 | JOIN sys.schemas s ON (t.schema_id = s.schema_id) 23 | WHERE s.name = '{0}' AND t.name = '{1}'", 24 | Name.Schema, 25 | Name.Object)); 26 | } 27 | 28 | public override bool CanModify(SchemaInstaller.InstallContext context, IDbConnection connection) 29 | { 30 | // we can drop a udt unless it is used in a table 31 | return connection.ExecuteScalarSql( 32 | "SELECT COUNT(*) FROM sys.types t JOIN sys.columns c ON (t.user_type_id = c.user_type_id) WHERE t.Name = @Name", 33 | new Dictionary() { { "Name", Name.Object } }) == 0; 34 | } 35 | 36 | public override void Drop(System.Data.IDbConnection connection) 37 | { 38 | connection.ExecuteSql(String.Format ("DROP TYPE {0}", Name.FullName)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Insight.Database.Schema; 6 | using System.Reflection; 7 | using System.Data.SqlClient; 8 | 9 | namespace Insight.Database.Schema.Sample 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder("Database=.;Initial Catalog=InsightTest;Integrated Security=true"); 16 | 17 | SchemaInstaller.CreateDatabase(connectionString.ConnectionString); 18 | 19 | using (SqlConnection connection = new SqlConnection(connectionString.ConnectionString)) 20 | { 21 | connection.Open(); 22 | 23 | // make sure our database exists 24 | SchemaInstaller installer = new SchemaInstaller(connection); 25 | new SchemaEventConsoleLogger().Attach(installer); 26 | 27 | // load the schema from the embedded resources in this project 28 | SchemaObjectCollection schema = new SchemaObjectCollection(); 29 | schema.Load(Assembly.GetExecutingAssembly()); 30 | 31 | // install the schema 32 | Console.WriteLine("Installing"); 33 | installer.Install("BeerGarten", schema); 34 | 35 | // uninstall the schema 36 | if (args.Length > 0 && args[0].ToUpperInvariant() == "UNINSTALL") 37 | { 38 | Console.WriteLine("Uninstalling"); 39 | installer.Uninstall("BeerGarten"); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Index.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Index : SchemaImpl 11 | { 12 | public Index(string name, string sql) : base(name, sql, 3) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@"SELECT COUNT(*) 19 | FROM sys.indexes i 20 | JOIN sys.objects t ON (i.object_id = t.object_id) 21 | JOIN sys.schemas s ON (t.schema_id = s.schema_id) 22 | WHERE s.Name = '{0}' AND t.name = '{1}' AND i.name = '{2}'", 23 | Name.Schema, 24 | Name.Table, 25 | Name.Object)); 26 | } 27 | 28 | public override bool CanModify(SchemaInstaller.InstallContext context, IDbConnection connection) 29 | { 30 | // azure can't drop the clustered index, so we have to warn if we are attempting to modify that 31 | if (context.IsAzure) 32 | { 33 | if (Sql.IndexOf("NONCLUSTERED", StringComparison.OrdinalIgnoreCase) == -1 && Sql.IndexOf("CLUSTERED", StringComparison.OrdinalIgnoreCase) != -1) 34 | return false; 35 | } 36 | 37 | return true; 38 | } 39 | 40 | public override void Drop(IDbConnection connection) 41 | { 42 | connection.ExecuteSql(String.Format(@"DROP INDEX {1} ON {0}", 43 | Name.SchemaQualifiedTable, 44 | Name.ObjectFormatted)); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/PartitionScheme.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class PartitionScheme : SchemaImpl 12 | { 13 | public PartitionScheme(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | public override bool Exists(IDbConnection connection) 18 | { 19 | return 0 < connection.ExecuteScalarSql(String.Format(@" 20 | SELECT COUNT (*) 21 | FROM sys.partition_schemes 22 | WHERE name = '{0}'", 23 | Name.Object)); 24 | } 25 | 26 | public override bool CanModify(SchemaInstaller.InstallContext context, IDbConnection connection) 27 | { 28 | // we can drop a scheme as long as there are no tables using it 29 | return connection.ExecuteScalarSql(@"SELECT COUNT(*) FROM sys.partition_schemes s 30 | WHERE s.name = @Name AND ( 31 | s.data_space_id IN (SELECT data_space_id FROM sys.indexes) OR 32 | s.data_space_id IN (SELECT lob_data_space_id FROM sys.tables) OR 33 | s.data_space_id IN (SELECT filestream_data_space_id FROM sys.tables)) 34 | ", new Dictionary() { { "Name", Name.Object } }) == 0; 35 | } 36 | 37 | public override void Drop(IDbConnection connection) 38 | { 39 | connection.ExecuteSql(String.Format(@"DROP PARTITION SCHEME {0}", Name.ObjectFormatted)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Installer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Insight.Database.Schema.Installer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Insight.Database.Schema.Installer")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c1acb259-f9b3-448c-bdad-f603c76a34da")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Insight.Database.Schema 5 | 2.0.0 6 | Insight.Database.Schema 7 | Jon Wagner 8 | A database installer engine that automatically handles most installation and upgrade issues, such as script ordering, and table and procedure updates. Easier than EntityFramework code migrations. 9 | en-US 10 | http://github.com/jonwagner/Insight.Database.Schema 11 | http://opensource.org/licenses/ms-pl.html 12 | Insight orm sql sqlserver schema installer code migration 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Insight.Database.Schema.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Insight.Database.Schema.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("312d080e-0720-49c2-a794-0cfceb43ace2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Insight.Database.Schema.Sample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Insight.Database.Schema.Sample")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f756c9f5-1f18-4268-8e8f-a3e79794464d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Verifier/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Insight.Database.Schema.Verifier")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Insight.Database.Schema.Verifier")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("47d3bb7c-f81e-4dbd-8d06-9ae28f85f54a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/PrimaryKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class PrimaryKey : SchemaImpl 11 | { 12 | public PrimaryKey(string name, string sql) : base(name, sql, 3) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@"SELECT COUNT(*) 19 | FROM sys.indexes i 20 | JOIN sys.tables t ON (i.object_id = t.object_id) 21 | JOIN sys.schemas s ON (t.schema_id = s.schema_id) 22 | WHERE s.Name = '{0}' AND t.name = '{1}' AND i.name = '{2}'", 23 | Name.Schema, 24 | Name.Table, 25 | Name.Object)); 26 | } 27 | 28 | public override bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 29 | { 30 | // azure can't drop the clustered index, so we have to warn if we are attempting to modify that 31 | if (context.IsAzure) 32 | { 33 | if (Sql.IndexOf("NONCLUSTERED", StringComparison.OrdinalIgnoreCase) == -1 && Sql.IndexOf("CLUSTERED", StringComparison.OrdinalIgnoreCase) != -1) 34 | return false; 35 | } 36 | 37 | return 0 == connection.ExecuteScalarSql(String.Format(@"SELECT COUNT(*) 38 | FROM sys.xml_indexes i 39 | WHERE i.object_id = OBJECT_ID('{0}')", 40 | Name.SchemaQualifiedTable)); 41 | } 42 | 43 | public override void Drop(IDbConnection connection) 44 | { 45 | connection.ExecuteSql(String.Format(@"ALTER TABLE {0} DROP CONSTRAINT {1}", 46 | Name.SchemaQualifiedTable, 47 | Name.ObjectFormatted)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Default.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class Default : SchemaImpl 11 | { 12 | public Default(string name, string sql) : base(name, sql, 3) 13 | { 14 | } 15 | 16 | public override bool Exists(IDbConnection connection) 17 | { 18 | return 0 < connection.ExecuteScalarSql(String.Format(@"SELECT COUNT(*) 19 | FROM sys.default_constraints d 20 | JOIN sys.schemas s ON (d.schema_id = s.schema_id) 21 | JOIN sys.objects o ON (d.parent_object_id = o.object_id) 22 | JOIN sys.columns c ON (c.object_id = o.object_id AND c.column_id = d.parent_column_id) 23 | WHERE s.Name = '{0}' AND o.name = '{1}' AND c.name = '{2}'", 24 | Name.Schema, 25 | Name.Table, 26 | Name.Object)); 27 | } 28 | 29 | public override void Drop(IDbConnection connection) 30 | { 31 | connection.ExecuteSql(String.Format(@" 32 | -- ALTER TABLE DROP DEFAULT ON COLUMN 33 | DECLARE @Name[nvarchar](256) 34 | SELECT @Name = d.name 35 | FROM sys.default_constraints d 36 | JOIN sys.schemas s ON (d.schema_id = s.schema_id) 37 | JOIN sys.objects o ON (d.parent_object_id = o.object_id) 38 | JOIN sys.columns c ON (c.object_id = o.object_id AND c.column_id = d.parent_column_id) 39 | WHERE s.name = '{0}' AND o.name = '{1}' AND c.name = '{2}' 40 | DECLARE @sql[nvarchar](MAX) = 'ALTER TABLE {3} DROP CONSTRAINT [' + @Name + ']' 41 | EXEC sp_executesql @sql 42 | ", 43 | Name.Schema, 44 | Name.Table, 45 | Name.Object, 46 | Name.SchemaQualifiedTable)); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/AutoProc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace Insight.Database.Schema.Implementation 9 | { 10 | class AutoProc : SchemaImpl 11 | { 12 | public AutoProc(string name, string sql) : base(name, sql, 2) 13 | { 14 | } 15 | 16 | public override void Install(IDbConnection connection, IEnumerable objects) 17 | { 18 | // for auto-procs, convert the comment into a list of stored procedures 19 | var sql = new Insight.Database.Schema.AutoProc(Name.Original, new SqlColumnDefinitionProvider(connection), objects).Sql; 20 | if (sql.Length == 0) 21 | return; 22 | 23 | foreach (string s in _goSplit.Split(sql).Where(piece => !String.IsNullOrWhiteSpace(piece))) 24 | connection.ExecuteSql(s); 25 | } 26 | 27 | public override bool Exists(IDbConnection connection) 28 | { 29 | return new Insight.Database.Schema.AutoProc(Name.Original, null, null).GetProcs().All(tuple => 30 | { 31 | switch (tuple.Item1) 32 | { 33 | case Insight.Database.Schema.AutoProc.ProcTypes.Table: 34 | case Insight.Database.Schema.AutoProc.ProcTypes.IdTable: 35 | return new UserDefinedType(tuple.Item2, null).Exists(connection); 36 | 37 | default: 38 | return new StoredProcedure(tuple.Item2, null).Exists(connection); 39 | } 40 | }); 41 | } 42 | 43 | public override void Drop(IDbConnection connection) 44 | { 45 | var sql = new Insight.Database.Schema.AutoProc(Name.Original, new SqlColumnDefinitionProvider(connection), null).DropSql; 46 | 47 | foreach (string s in _goSplit.Split(sql).Where(piece => !String.IsNullOrWhiteSpace(piece))) 48 | connection.ExecuteSql(s); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/Moq.4.0.10827/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD 2 | http://code.google.com/p/moq/ 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, 6 | with or without modification, are permitted provided 7 | that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the 10 | above copyright notice, this list of conditions and 11 | the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce 14 | the above copyright notice, this list of conditions 15 | and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the 19 | names of its contributors may be used to endorse 20 | or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | SUCH DAMAGE. 37 | 38 | [This is the BSD license, see 39 | http://www.opensource.org/licenses/bsd-license.php] -------------------------------------------------------------------------------- /Insight.Database.Schema/ColumnDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Insight.Database.Schema 7 | { 8 | /// 9 | /// Represents a column in the database. 10 | /// 11 | /// This class is framework code and is not intended to be used by external code. 12 | public class ColumnDefinition 13 | { 14 | /// 15 | /// The name of the column. 16 | /// 17 | public string Name { get; set; } 18 | 19 | /// 20 | /// The type of the column, including the precision/size. 21 | /// 22 | public string SqlType { get; set; } 23 | 24 | /// 25 | /// True if the column is a key field. 26 | /// 27 | public bool IsKey { get; set; } 28 | 29 | /// 30 | /// True if the column is not updatable. 31 | /// 32 | public bool IsReadOnly { get; set; } 33 | 34 | /// 35 | /// True if the column is an identity. 36 | /// 37 | public bool IsIdentity { get; set; } 38 | 39 | /// 40 | /// True if the column is a rowversion. 41 | /// 42 | public bool IsRowVersion { get; set; } 43 | 44 | /// 45 | /// True if the column is nullable on update. 46 | /// 47 | public bool IsUpdateNullable { get; set; } 48 | 49 | /// 50 | /// True if the column has a default 51 | /// 52 | public bool HasDefault { get; set; } 53 | 54 | /// 55 | /// The name of the column formatted properly for use as a SQL column. 56 | /// 57 | public string ColumnName { get { return SqlParser.FormatSqlName(Name); } } 58 | 59 | /// 60 | /// The name of the column formatted properly for use as a SQL parameter. 61 | /// 62 | public string ParameterName { get { return "@" + Name; } } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/runFile.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | #endregion 8 | 9 | namespace Insight.Database.Schema 10 | { 11 | /// 12 | /// Arguments for a Schema change event 13 | /// 14 | public class SchemaEventArgs : EventArgs 15 | { 16 | /// 17 | /// The type of Schema event 18 | /// 19 | /// The type of Schema event 20 | public SchemaEventType EventType { get { return _eventType; } } 21 | private SchemaEventType _eventType; 22 | 23 | /// 24 | /// The name of the schema object 25 | /// 26 | /// The type of Schema event 27 | public string ObjectName { get { return _objectName; } } 28 | private string _objectName; 29 | 30 | /// 31 | /// The schema object being updated. 32 | /// 33 | /// The type of Schema event 34 | /// This is null for a drop object event 35 | public SchemaObject SchemaObject { get { return _schemaObject; } } 36 | private SchemaObject _schemaObject; 37 | 38 | /// 39 | /// In the case of a DropFailed event, the exception that was thrown. 40 | /// 41 | /// The exception that was thrown. 42 | public Exception Exception { get; internal set; } 43 | 44 | internal SchemaEventArgs (SchemaEventType eventType, string objectName) 45 | { 46 | _eventType = eventType; 47 | _objectName = objectName; 48 | } 49 | 50 | internal SchemaEventArgs (SchemaEventType eventType, SchemaObject schemaObject) 51 | { 52 | _eventType = eventType; 53 | _schemaObject = schemaObject; 54 | _objectName = schemaObject.Name; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Insight.Database.Schema/LambdaComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Insight.Database.Schema 8 | { 9 | /// 10 | /// Implements IEqualityComparer with a lambda expression. 11 | /// 12 | /// The type to compare. 13 | class LambdaComparer : IEqualityComparer 14 | { 15 | private readonly Func _expression; 16 | 17 | public LambdaComparer(Func lambda) 18 | { 19 | _expression = lambda; 20 | } 21 | 22 | public bool Equals(T x, T y) 23 | { 24 | return _expression(x, y); 25 | } 26 | 27 | public int GetHashCode(T obj) 28 | { 29 | return 0; 30 | } 31 | } 32 | 33 | static class LambdaComparerExtensions 34 | { 35 | /// 36 | /// Returns all items in the first collection except the ones in the second collection that match the lambda condition. 37 | /// 38 | /// The type. 39 | /// The first list. 40 | /// The second list. 41 | /// The filter expression. 42 | /// The filtered list. 43 | public static IEnumerable Except(this IEnumerable listA, IEnumerable listB, Func lambda) 44 | { 45 | return listA.Except(listB, new LambdaComparer(lambda)); 46 | } 47 | 48 | /// 49 | /// Returns all items in the first collection that intersect the ones in the second collection that match the lambda condition. 50 | /// 51 | /// The type. 52 | /// The first list. 53 | /// The second list. 54 | /// The filter expression. 55 | /// The filtered list. 56 | public static IEnumerable Intersect(this IEnumerable listA, IEnumerable listB, Func lambda) 57 | { 58 | return listA.Intersect(listB, new LambdaComparer(lambda)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-console.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 24 | 25 | 26 | 29 | 31 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-agent.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 24 | 25 | 26 | 29 | 31 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-console-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 24 | 25 | 26 | 29 | 31 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-agent-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 24 | 25 | 26 | 29 | 31 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/DatabaseTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using NUnit.Framework; 7 | using System.Transactions; 8 | using System.Configuration; 9 | using System.Data.SqlClient; 10 | 11 | namespace Insight.Database.Schema.Tests 12 | { 13 | /// 14 | /// Test create/drop database. 15 | /// 16 | [TestFixture] 17 | public class DatabaseTests : BaseInstallerTest 18 | { 19 | #region DatabaseExists Tests 20 | [Test] 21 | public void DatabaseExistsReturnsTrueForMaster([ValueSource("ConnectionStrings")] string connectionString) 22 | { 23 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); 24 | builder.InitialCatalog = "master"; 25 | 26 | Assert.True(SchemaInstaller.DatabaseExists(builder.ConnectionString)); 27 | } 28 | 29 | [Test] 30 | public void DatabaseExistsReturnsTrueForInvalid([ValueSource("ConnectionStrings")] string connectionString) 31 | { 32 | SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString); 33 | builder.InitialCatalog = "fhjasjkl"; 34 | 35 | Assert.False(SchemaInstaller.DatabaseExists(builder.ConnectionString)); 36 | } 37 | #endregion 38 | 39 | #region Create Tests 40 | [Test] 41 | public void TestCreateDatabase([ValueSource("ConnectionStrings")] string connectionString) 42 | { 43 | TestWithDrop(connectionString, () => 44 | { 45 | // drop the database if it already exists 46 | if (SchemaInstaller.DatabaseExists(connectionString)) 47 | SchemaInstaller.DropDatabase(connectionString); 48 | 49 | // create the database 50 | Assert.True(SchemaInstaller.CreateDatabase(connectionString)); 51 | 52 | // make sure the database exises 53 | Assert.True(SchemaInstaller.DatabaseExists(connectionString)); 54 | 55 | // create the database again, it should return false 56 | Assert.False(SchemaInstaller.CreateDatabase(connectionString)); 57 | }); 58 | } 59 | #endregion 60 | 61 | #region Drop Tests 62 | [Test] 63 | public void TestDropDatabase([ValueSource("ConnectionStrings")] string connectionString) 64 | { 65 | TestWithDrop(connectionString, () => 66 | { 67 | // create the database if it doesn't exist 68 | if (!SchemaInstaller.DatabaseExists(connectionString)) 69 | SchemaInstaller.CreateDatabase(connectionString); 70 | 71 | // drop the database 72 | Assert.True(SchemaInstaller.DropDatabase(connectionString)); 73 | 74 | // make sure the database doesn't exist 75 | Assert.False(SchemaInstaller.DatabaseExists(connectionString)); 76 | 77 | // drop the database again, it should return false 78 | Assert.False(SchemaInstaller.DropDatabase(connectionString)); 79 | }); 80 | } 81 | #endregion 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/BaseInstallerTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Configuration; 5 | using System.Data; 6 | using System.Data.Common; 7 | using System.Data.SqlClient; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Transactions; 12 | 13 | namespace Insight.Database.Schema.Tests 14 | { 15 | /// 16 | /// Base test case support classes 17 | /// 18 | public class BaseInstallerTest 19 | { 20 | /// 21 | /// The list of connection strings that will be used to run tests. 22 | /// 23 | protected IEnumerable ConnectionStrings { get { return _connectionStrings; } } 24 | private static readonly ReadOnlyCollection _connectionStrings = new ReadOnlyCollection( 25 | ConfigurationManager.ConnectionStrings.OfType() 26 | .Where(c => c.Name.Contains("Test")) 27 | .Select(c => c.ConnectionString) 28 | .ToList()); 29 | 30 | /// 31 | /// The schema group to use for the test cases. 32 | /// 33 | protected static string TestSchemaGroup = "test"; 34 | 35 | /// 36 | /// Run a test and clean up the databases when complete. 37 | /// 38 | /// The connection string for the database. 39 | /// The test to run. 40 | protected static void TestWithDrop(string connectionString, Action action) 41 | { 42 | try 43 | { 44 | action(); 45 | } 46 | finally 47 | { 48 | SchemaInstaller.DropDatabase(connectionString); 49 | } 50 | } 51 | 52 | /// 53 | /// Run a test and clean up the databases when complete. 54 | /// 55 | /// The connection string for the database. 56 | /// The test to run. 57 | internal static void TestWithRollback(string connectionString, Action action) 58 | { 59 | // make sure the database exists 60 | if (!SchemaInstaller.DatabaseExists(connectionString)) 61 | SchemaInstaller.CreateDatabase(connectionString); 62 | 63 | // do all of the work in a transaction so we can clean up our changes 64 | using (TransactionScope transaction = new TransactionScope()) 65 | using (SqlConnection connection = new SqlConnection(connectionString)) 66 | using (RecordingDbConnection recordingConnection = new RecordingDbConnection(connection)) 67 | { 68 | recordingConnection.Open(); 69 | try 70 | { 71 | action(recordingConnection); 72 | } 73 | finally 74 | { 75 | Console.WriteLine("== BEGIN SCRIPT ============================"); 76 | Console.WriteLine(recordingConnection.ScriptLog.ToString()); 77 | Console.WriteLine("== END SCRIPT ============================"); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Installer/Insight.Database.Schema.Installer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C} 8 | Exe 9 | Properties 10 | Insight.Database.Schema.Installer 11 | InsightInstaller 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {fbd1c65f-9054-42c7-ba0e-48a922c4c747} 53 | Insight.Database.Schema 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaException.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Runtime.Serialization; 6 | using System.Text; 7 | using System.Globalization; 8 | 9 | #endregion 10 | 11 | namespace Insight.Database.Schema 12 | { 13 | #region SchemaParsingException Class 14 | /// 15 | /// Represents errors in parsing a SQL script 16 | /// 17 | [Serializable] 18 | public class SchemaException : Exception 19 | { 20 | /// 21 | /// Construct a SchemaException 22 | /// 23 | public SchemaException () 24 | { 25 | } 26 | 27 | /// 28 | /// Construct a SchemaException with a message 29 | /// 30 | /// The exception error message 31 | public SchemaException (string message) : base (message) 32 | { 33 | } 34 | 35 | /// 36 | /// Construct a SchemaException with a message 37 | /// 38 | /// The exception error message 39 | /// The base exception 40 | public SchemaException (string message, Exception innerException) : base (message, innerException) 41 | { 42 | } 43 | 44 | /// 45 | /// Construct a SchemaException with a message and the error sql 46 | /// 47 | /// The exception error message 48 | /// The sql script that could not be parsed 49 | public SchemaException(string message, string sql) 50 | : base(String.Format(CultureInfo.InvariantCulture, message, sql)) 51 | { 52 | _sql = sql; 53 | } 54 | 55 | /// 56 | /// Construct a SchemaException with a message and the error sql 57 | /// 58 | /// Serialization information 59 | /// Serialization context 60 | protected SchemaException(SerializationInfo info, StreamingContext context) 61 | : base(info, context) 62 | { 63 | } 64 | 65 | /// 66 | /// The SQL script that caused the error 67 | /// 68 | /// 69 | public string Sql { get { return _sql; } } 70 | private string _sql; 71 | 72 | /// 73 | /// Implements the serialization of the Exception data. 74 | /// 75 | /// The information object to append to. 76 | /// The streaming context to write to. 77 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 78 | { 79 | base.GetObjectData(info, context); 80 | 81 | // add the SQL that was being parsed 82 | info.AddValue("_sql", _sql); 83 | } 84 | } 85 | #endregion 86 | } 87 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.1 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Insight.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Insight.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaParsingException.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Runtime.Serialization; 6 | using System.Text; 7 | using System.Globalization; 8 | 9 | #endregion 10 | 11 | namespace Insight.Database.Schema 12 | { 13 | #region SchemaParsingException Class 14 | /// 15 | /// Represents errors in parsing a SQL script 16 | /// 17 | [Serializable] 18 | public class SchemaParsingException : Exception 19 | { 20 | /// 21 | /// Construct a SchemaParsingException 22 | /// 23 | public SchemaParsingException () 24 | { 25 | } 26 | 27 | /// 28 | /// Construct a SchemaParsingException with a message 29 | /// 30 | /// The exception error message 31 | public SchemaParsingException (string message) : base (message) 32 | { 33 | } 34 | 35 | /// 36 | /// Construct a SchemaParsingException with a message 37 | /// 38 | /// The exception error message 39 | /// The base exception 40 | public SchemaParsingException (string message, Exception innerException) : base (message, innerException) 41 | { 42 | } 43 | 44 | /// 45 | /// Construct a SchemaParsingException with a message and the error sql 46 | /// 47 | /// The exception error message 48 | /// The sql script that could not be parsed 49 | public SchemaParsingException(string message, string sql) 50 | : base(String.Format(CultureInfo.InvariantCulture, message, sql)) 51 | { 52 | _sql = sql; 53 | } 54 | 55 | /// 56 | /// Construct a SchemaParsingException with a message and the error sql 57 | /// 58 | /// Serialization information 59 | /// Serialization context 60 | protected SchemaParsingException (SerializationInfo info, StreamingContext context) : base (info, context) 61 | { 62 | } 63 | 64 | /// 65 | /// The SQL script that caused the error 66 | /// 67 | /// 68 | public string Sql { get { return _sql; } } 69 | private string _sql; 70 | 71 | /// 72 | /// Implements the serialization of the Exception data. 73 | /// 74 | /// The information object to append to. 75 | /// The streaming context to write to. 76 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 77 | { 78 | base.GetObjectData(info, context); 79 | 80 | // add the SQL that was being parsed 81 | info.AddValue("_sql", _sql); 82 | } 83 | } 84 | #endregion 85 | } 86 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit-agent.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 30 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 69 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/pnunit-launcher.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 30 | 32 | 33 | 34 | 37 | 39 | 40 | 41 | 42 | 45 | 47 | 48 | 49 | 50 | 53 | 55 | 56 | 57 | 58 | 61 | 63 | 64 | 65 | 66 | 69 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /.hgtags: -------------------------------------------------------------------------------- 1 | 5e4ddcbfbd2b78a560b84f5b30050f2a9121dd88 Version 1.0.1 2 | 4031ecdd1c02d5bc9e5ae359992dd69a4fb04769 Version 1.0.2 3 | ecfad38b4cb6b4f720546fdafc2b4d858af43195 Version 1.0.3 4 | b111e60e44f736a5f7cfab0c2c6001cdee96da90 Version 1.0.4 5 | 249b78592d69d3d4bf070857807ff8c1b3e2cf62 Version 1.0.5 6 | b4d4eb5d3fe91f85df9c8d8b008bff40afd0aeec Version 1.0.6 7 | c83e1e89bdf810e269436a0290e38b6a0594f279 Version 1.0.7 8 | 7a9cd869b1b2ddd672bc33a9b5a76ae2e3c8bfd8 Version 1.0.8 9 | e41312b456e7ec8b5bc6fd8c6d77a35e8783766f Version 1.0.9 10 | d13f0a41b69846edca2b1f37b729049df9f2264b Version 1.0.10 11 | b5ed27bcd0705acdf57af68a7073279b4dc5b3c1 Version 1.0.11 12 | 0526eb76242696298e9ee4140ff9eea930856772 Version 1.0.12 13 | c8e7af9dd7e29e12adcd0f0a32d744dc2a6e5f38 Version 1.0.13 14 | a55d3a5abbead8b6a222daad1921252da8222bec Version 1.0.14 15 | 821c59d83416b824038f8f0312e28f91afeeb74a Version 1.0.15 16 | cfc4ae0885260dfe00be704de22bb2b1c7f1fb3f Version 1.0.16 17 | dfea6a3b42be9fb52d7de7d0bda731d2f4137a73 Version 1.0.17 18 | 44b192ae01c12cc9c309504c72a0cab8f1227faf Version 1.0.18 19 | ae730615c5a53cbb98908f598c25ee4073458d10 Version 1.0.19 20 | 973f89697b7653236ba78dbbde8be0ce76445902 Version 1.0.20 21 | 5698a3a9f7609806b1925a18da81824aa3986b04 Version 1.0.21 22 | a65e3d0066462ae0fc858a53195c5a65b14edc27 Version 1.0.22 23 | 8d98491b2f793730669d8971771daa3c43c5e582 Version 1.0.23 24 | 8b684124731be34a8499e575fe23d522985ebce4 Version 1.0.24 25 | 545bdf79747805133639757cba896b0e33142833 Version 1.0.25 26 | 79e0d34d8d0e70843edb8396e9e130fb6db6a9c9 Version 1.0.26 27 | dee91b2c2c5866a12d3c926984430903acaf9080 Version 1.0.27 28 | 303a7b6ad3eebfd5b486b6cbbf7b3e6dfd94ec85 Version 1.0.28 29 | c5d5721657b812666dd875aaa9d2ae56f90a43ff Version 1.0.29 30 | 3dbf693e4d056fbe7ba8d6c129ed4d357ba65878 Version 1.0.30 31 | 894fca4c726217d2ed7f977b1acd9b78a8f55fa7 Version 1.0.31 32 | 192d936e8baf8d0a9d5003bc728236e59a4f9342 Version 1.0.32 33 | a843eee6ff188897dc986e53326ea043488f472d Version 1.0.33 34 | d6d50fd5174010533232bcdbeece355cd50626d7 Version 1.0.35 35 | 1913031ca15d7138611af06a506abe12bee09214 Version 1.0.36 36 | 70182d27f26da78e07180864a6bffc864c8dd5ef Version 1.0.37 37 | eec9b7a2237049340aeff9cc7bc289a18e2c3e06 Version 1.0.38 38 | 7675ce28cb3bc9f1e2582d1b3662de49c0fc2d48 Version 1.0.39 39 | 213b9ec5fd91c2383140c4b64ab9153136c839ad Version 1.0.40 40 | 3851adb2c0f52ccf40e40e974d797fe5a69b8bb5 Version 1.0.41 41 | bae702c80195555e8284a150d0c7d66606331799 Version 1.0.42 42 | 8b41b58cda9172fc4219ec0ef6d8261e1c1208a6 Version 1.0.43 43 | 70a69b1fce4b8b91aa490018fbb180b61ff0e52b Version 1.0.44 44 | ab6f5fc8a811b0dbae74936264cea19e59b7847f Version 1.0.45 45 | 2d0297caf946905400cc1e124b86a35d7eb49efa Version 1.0.46 46 | 26620351f1e89ace8378da67da946495c0249f34 Version 1.0.47 47 | 8c1e7b850f46da3cb81d784d67ba0b6c5de2bbbc Version 1.0.48 48 | d5ef0f4380c409776397699f8b0b351b91611bad Version 1.0.49 49 | dd129be56543fd83a795a461d9ee1ef78a350423 Version 1.0.50 50 | bc5490b578b131a1aa066cd1afa766031f45d044 Version 1.0.51 51 | 812358c282b49b125feab7b0ce28c789d93067d4 Version 1.0.52 52 | cb26259f8e436dbc73962dd53ec232d57eae1383 Version 1.0.53 53 | 8fde7d2b4756511c8d394657362bd0c0349ef2e8 Version 1.0.54 54 | d2c4e22631b01fc03582c7e3e2565fadca5ca43f Version 1.0.55 55 | 6be85245f52c318ef6d7ca638284c9b32a2ec108 Version 1.0.56 56 | -------------------------------------------------------------------------------- /Insight.Database.Schema/ConnectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.Common; 5 | using System.Dynamic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Insight.Database.Schema 11 | { 12 | internal static class ConnectionExtensions 13 | { 14 | public static bool IsAzure(this string connectionString) 15 | { 16 | return connectionString.Contains("windows.net"); 17 | } 18 | public static bool IsAzure(this IDbConnection connection) 19 | { 20 | return connection.ConnectionString.IsAzure(); 21 | } 22 | 23 | public static DbConnection Unwrap(this DbConnection connection) 24 | { 25 | RecordingDbConnection recording = connection as RecordingDbConnection; 26 | if (recording != null) 27 | return recording.InnerConnection.Unwrap(); 28 | 29 | return connection; 30 | } 31 | 32 | public static int ExecuteSql(this IDbConnection connection, string sql) 33 | { 34 | var cmd = connection.CreateCommand(); 35 | cmd.CommandText = sql; 36 | cmd.CommandType = CommandType.Text; 37 | 38 | return cmd.ExecuteNonQuery(); 39 | } 40 | 41 | public static T ExecuteScalarSql(this IDbConnection connection, string sql, IDictionary parameters = null) 42 | { 43 | var cmd = connection.CreateCommand(); 44 | cmd.CommandText = sql; 45 | cmd.CommandType = CommandType.Text; 46 | 47 | if (parameters != null) 48 | CreateParameters(parameters, cmd); 49 | 50 | return (T)cmd.ExecuteScalar(); 51 | } 52 | 53 | public static IDataReader GetReaderSql(this IDbConnection connection, string sql) 54 | { 55 | var cmd = connection.CreateCommand(); 56 | cmd.CommandText = sql; 57 | cmd.CommandType = CommandType.Text; 58 | 59 | return cmd.ExecuteReader(); 60 | } 61 | 62 | public static IList QuerySql(this IDbConnection connection, string sql, IDictionary parameters) 63 | { 64 | var cmd = connection.CreateCommand(); 65 | cmd.CommandText = sql; 66 | cmd.CommandType = CommandType.Text; 67 | 68 | CreateParameters(parameters, cmd); 69 | 70 | var results = new List(); 71 | 72 | using (var reader = cmd.ExecuteReader()) 73 | { 74 | while (reader.Read()) 75 | { 76 | var expando = new FastExpando(); 77 | var dict = (IDictionary)expando; 78 | for (int i = 0; i < reader.FieldCount; i++) 79 | { 80 | object value = reader.GetValue(i); 81 | if (value == DBNull.Value) 82 | value = null; 83 | dict[reader.GetName(i)] = value; 84 | } 85 | results.Add(expando); 86 | } 87 | } 88 | 89 | return results; 90 | } 91 | 92 | private static void CreateParameters(IDictionary parameters, IDbCommand cmd) 93 | { 94 | if (parameters == null) 95 | return; 96 | 97 | foreach (var pair in parameters) 98 | { 99 | var p = cmd.CreateParameter(); 100 | p.ParameterName = "@" + pair.Key; 101 | if (pair.Value != null) 102 | p.Value = pair.Value; 103 | else 104 | p.Value = DBNull.Value; 105 | cmd.Parameters.Add(p); 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Singularizer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace Insight.Database.Schema 8 | { 9 | /// 10 | /// Converts plural table names to singular function names. 11 | /// 12 | class Singularizer 13 | { 14 | /// 15 | /// Words that should stay the same. 16 | /// 17 | private static readonly IList Unpluralizables = 18 | new List 19 | { 20 | "EQUIPMENT", 21 | "INFORMATION", 22 | "RICE", 23 | "MONEY", 24 | "SPECIES", 25 | "SERIES", 26 | "FISH", 27 | "SHEEP", 28 | "DEER" 29 | }; 30 | 31 | /// 32 | /// Mappings from plural to single. 33 | /// 34 | private static readonly IDictionary Singularizations = 35 | new Dictionary 36 | { 37 | // Start with the rarest cases, and move to the most common 38 | {"people", "Person"}, 39 | {"oxen", "Ox"}, 40 | {"children", "Child"}, 41 | {"feet", "Foot"}, 42 | {"teeth", "Tooth"}, 43 | {"geese", "Goose"}, 44 | // and now the more standard rules. 45 | {"wives?", "wife"}, 46 | {"(.*)lves?", "$1lf"}, 47 | // ie, wolf, wife 48 | {"(.*)men$", "$1man"}, 49 | {"(.+[aeiou])ys$", "$1y"}, 50 | {"(.+[^aeiou])ies$", "$1y"}, 51 | {"(.+z)zes$", "$1"}, 52 | {"(.+)zes$", "$1ze"}, 53 | {"([m|l])ice$", "$1ouse"}, 54 | {"matrices", @"Matrix"}, 55 | {"indices", @"Index"}, 56 | {"(.+[^aeiou])ices$","$1ice"}, 57 | {"(.*)ices", @"$1ex"}, 58 | // ie, matrix, index 59 | {"(octop|vir)i$", "$1us"}, 60 | {"(.+(ase))s$", @"$1"}, 61 | {"(.+(s|x|sh|ch))es$", @"$1"}, 62 | {"(.+)s", @"$1"} 63 | }; 64 | 65 | /// 66 | /// Converts a word to its plural form or keeps it the same. 67 | /// 68 | /// The word to singularize. 69 | /// The singular form of the word. 70 | public static string Singularize(string word) 71 | { 72 | if (Unpluralizables.Contains(word.ToUpperInvariant())) 73 | { 74 | return word; 75 | } 76 | 77 | foreach (var singularization in Singularizations) 78 | { 79 | if (Regex.IsMatch(word, singularization.Key, RegexOptions.IgnoreCase)) 80 | { 81 | return Regex.Replace(word, singularization.Key, singularization.Value, RegexOptions.IgnoreCase); 82 | } 83 | } 84 | 85 | return word; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 36 | 38 | 39 | 40 | 43 | 45 | 46 | 47 | 48 | 51 | 53 | 54 | 55 | 56 | 59 | 61 | 62 | 63 | 64 | 67 | 69 | 70 | 71 | 72 | 75 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/nunit-x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 36 | 38 | 39 | 40 | 43 | 45 | 46 | 47 | 48 | 51 | 53 | 54 | 55 | 56 | 59 | 61 | 62 | 63 | 64 | 67 | 69 | 70 | 71 | 72 | 75 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SqlName.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace Insight.Database.Schema 8 | { 9 | public class SqlName : IEquatable 10 | { 11 | public string Original { get; private set; } 12 | public string Schema { get; private set; } 13 | public string Table { get; private set; } 14 | public string Object { get; private set; } 15 | 16 | public string SchemaFormatted { get { return SqlParser.FormatSqlName(Schema); } } 17 | public string TableFormatted { get { return SqlParser.FormatSqlName(Table); } } 18 | public string ObjectFormatted { get { return SqlParser.FormatSqlName(Object); } } 19 | 20 | public string SchemaQualifiedTable 21 | { 22 | get 23 | { 24 | if (!String.IsNullOrWhiteSpace(Schema)) 25 | return SchemaFormatted + "." + TableFormatted; 26 | else 27 | return TableFormatted; 28 | } 29 | } 30 | 31 | public string SchemaQualifiedObject 32 | { 33 | get 34 | { 35 | if (!String.IsNullOrWhiteSpace(Schema)) 36 | return SchemaFormatted + "." + ObjectFormatted; 37 | else 38 | return ObjectFormatted; 39 | } 40 | } 41 | 42 | public string FullName 43 | { 44 | get 45 | { 46 | string name = SchemaQualifiedTable; 47 | if (Table != Object) 48 | name += "." + ObjectFormatted; 49 | 50 | return name ?? Original; 51 | } 52 | } 53 | 54 | public SqlName(string fullName, int expectedParts) 55 | { 56 | Original = fullName; 57 | 58 | var split = SplitSqlName(fullName); 59 | if (split.Length < expectedParts) 60 | { 61 | fullName = "[dbo]." + fullName; 62 | split = SplitSqlName(fullName); 63 | } 64 | 65 | // in some special cases (autoproc, permissions), we just need the original 66 | if (split.Length > expectedParts) 67 | return; 68 | 69 | if (split.Length == 1) 70 | { 71 | Table = split[0]; 72 | Object = split[0]; 73 | } 74 | else if (split.Length == 2) 75 | { 76 | Schema = split[0]; 77 | Table = split[1]; 78 | Object = split[1]; 79 | } 80 | else if (split.Length == 3) 81 | { 82 | Schema = split[0]; 83 | Table = split[1]; 84 | Object = split[2]; 85 | } 86 | 87 | if (split.Length > 1 && String.IsNullOrWhiteSpace(Schema)) 88 | Schema = "dbo"; 89 | 90 | Schema = SqlParser.UnformatSqlName(Schema); 91 | Table = SqlParser.UnformatSqlName(Table); 92 | Object = SqlParser.UnformatSqlName(Object); 93 | } 94 | 95 | private static string[] SplitSqlName(string fullName) 96 | { 97 | var split = Regex.Matches(fullName, @"(\[[^\]]+\])|([\w\d]+)").OfType().Select(m => m.Value).ToArray(); 98 | return split; 99 | } 100 | 101 | public SqlName Append(string objectName) 102 | { 103 | if (Table != Object) throw new InvalidOperationException("Cannot get a child of an object that is not a table"); 104 | 105 | SqlName child = (SqlName)MemberwiseClone(); 106 | child.Object = SqlParser.UnformatSqlName(objectName); 107 | 108 | return child; 109 | } 110 | 111 | public bool Equals(SqlName other) 112 | { 113 | return String.Compare(Schema, other.Schema, StringComparison.OrdinalIgnoreCase) == 0 && 114 | String.Compare(Table, other.Table, StringComparison.OrdinalIgnoreCase) == 0 && 115 | String.Compare(Object, other.Object, StringComparison.OrdinalIgnoreCase) == 0; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Sample/Insight.Database.Schema.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D} 9 | Exe 10 | Properties 11 | Insight.Database.Schema.Sample 12 | Insight.Database.Schema.Sample 13 | v4.5 14 | 15 | 16 | 512 17 | 18 | 19 | x86 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | 29 | 30 | x86 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | false 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747} 58 | Insight.Database.Schema 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 84 | -------------------------------------------------------------------------------- /Build.psake.ps1: -------------------------------------------------------------------------------- 1 | $psake.use_exit_on_error = $true 2 | 3 | ######################################### 4 | # to build a new version 5 | # 1. git tag 1.0.x 6 | # 2. build package 7 | ######################################### 8 | 9 | properties { 10 | $baseDir = $psake.build_script_dir 11 | 12 | $version = git describe --abbrev=0 --tags 13 | $changeset = (git log -1 $version --pretty=format:%H) 14 | $assemblyversion = $version.Split('-', 2)[0] 15 | 16 | $outputDir = "$baseDir\Build\Output" 17 | $net40Path = "$baseDir\Insight.Database.Schema\bin\NET40" 18 | 19 | $framework = "$env:systemroot\Microsoft.NET\Framework\v4.0.30319\" 20 | $msbuild = $framework + "msbuild.exe" 21 | $configuration = "Release" 22 | $nuget = "nuget.exe" 23 | $nunit = Get-ChildItem "$baseDir\packages" -Recurse -Include nunit-console.exe 24 | } 25 | 26 | Task default -depends Build 27 | Task Build -depends Build40,Build45 28 | Task Test -depends Test40,Test45 29 | 30 | function Replace-Version { 31 | param ( 32 | [string] $Path 33 | ) 34 | 35 | (Get-Content $Path) | 36 | % { $_ -replace "\[assembly: AssemblyVersion\(`"(\d+\.?)*`"\)\]","[assembly: AssemblyVersion(`"$assemblyversion`")]" } | 37 | % { $_ -replace "\[assembly: AssemblyFileVersion\(`"(\d+\.?)*`"\)\]","[assembly: AssemblyFileVersion(`"$assemblyversion`")]" } | 38 | Set-Content $Path 39 | } 40 | 41 | function ReplaceVersions { 42 | Get-ChildItem $baseDir -Include AssemblyInfo.cs -Recurse |% { Replace-Version $_.FullName } 43 | } 44 | 45 | function RestoreVersions { 46 | Get-ChildItem $baseDir -Include AssemblyInfo.cs -Recurse |% { 47 | git checkout $_.FullName 48 | } 49 | } 50 | 51 | function Wipe-Folder { 52 | param ( 53 | [string] $Path 54 | ) 55 | 56 | if (Test-Path $Path) { Remove-Item $Path -Recurse } 57 | New-Item -Path $Path -ItemType Directory | Out-Null 58 | } 59 | 60 | Task Build40 { 61 | ReplaceVersions 62 | 63 | try { 64 | # build the NET40 binaries 65 | Exec { 66 | Invoke-Expression "$msbuild $baseDir\Insight.sln /p:Configuration=$configuration /p:TargetFrameworkVersion=v4.0 /p:DefineConstants=```"NODBASYNC``;CODE_ANALYSIS```" '/t:Clean;Build'" 67 | } 68 | 69 | # copy the binaries to the net40 folder 70 | Wipe-Folder $net40Path 71 | Copy-Item $baseDir\Insight.Database.Schema\bin\Release\*.* $net40Path 72 | Copy-Item $baseDir\Insight.Database.Schema.Tests\bin\Release\*.* $net40Path 73 | Copy-Item $baseDir\Insight.Database.Schema.Installer\bin\Release\*.* $net40Path 74 | } 75 | finally { 76 | RestoreVersions 77 | } 78 | } 79 | 80 | Task Build45 { 81 | ReplaceVersions 82 | 83 | try { 84 | # build the NET45 binaries 85 | Exec { 86 | Invoke-Expression "$msbuild $baseDir\Insight.sln '/p:Configuration=$configuration' '/t:Clean;Build'" 87 | } 88 | } 89 | finally { 90 | RestoreVersions 91 | } 92 | } 93 | 94 | Task Test40 -depends Build40 { 95 | Exec { 96 | Invoke-Expression "$nunit $net40Path\Insight.Database.Schema.Tests.dll" 97 | } 98 | } 99 | 100 | Task Test45 -depends Build45 { 101 | Exec { 102 | Invoke-Expression "$nunit $baseDir\Insight.Database.Schema.Tests\bin\$configuration\Insight.Database.Schema.Tests.dll" 103 | } 104 | } 105 | 106 | Task Package -depends Test { 107 | Wipe-Folder $outputDir 108 | 109 | # package nuget 110 | Exec { 111 | Invoke-Expression "$nuget pack $baseDir\Insight.Database.Schema.nuspec -OutputDirectory $outputDir -Version $version -NoPackageAnalysis" 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /packages/NUnit.2.6.0.12054/tools/NUnitTests.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 25 | 26 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 54 | 55 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/SqlParserTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | using NUnit.Framework; 8 | using System.IO; 9 | 10 | namespace Insight.Database.Schema.Tests 11 | { 12 | [TestFixture] 13 | public class SqlParserTests 14 | { 15 | #region Parser Tests 16 | /// 17 | /// Make sure that all forms of SQL names are detected properly. 18 | /// 19 | /// 20 | [Test] 21 | public void TestSqlNameParsing([Values ( 22 | "type::[AccountsTableType]", 23 | "type::[dbo].[AccountsTableType]", 24 | "dbo.Accounts", 25 | "Accounts", 26 | "foo.dbo.Accounts", 27 | "[Foo].dbo.Accounts" 28 | )] string name) 29 | { 30 | Regex regex = new Regex(SqlParser.SqlNameExpression, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled); 31 | 32 | Match m = regex.Match(name); 33 | Assert.IsTrue(m.Success); 34 | Assert.AreEqual(m.Value, name); 35 | } 36 | 37 | /// 38 | /// Make sure that we throw exceptions for all of the SQL we don't support. 39 | /// 40 | /// The sql to check. 41 | [Test] 42 | public void TestUnsupportedSql([Values( 43 | "ALTER TABLE Foo ADD CONSTRAINT CHECK (id > 0)", // unnamed explicit check constraints 44 | "CREATE TABLE Foo (id int, CHECK (id > 0))", // unnamed inline check constraints 45 | "ALTER TABLE Foo ADD PRIMARY KEY (ID)", // unnamed explicit primary key 46 | "CREATE TABLE Foo (id int, PRIMARY KEY (ID))", // unnamed inline primary key 47 | "ALTER TABLE Foo ADD FOREIGN KEY (ID)", // unnamed explicit foreign key 48 | "CREATE TABLE Foo (id int, FOREIGN KEY (ID))", // unnamed inline foreign key 49 | "" 50 | )] string sql) 51 | { 52 | if (sql == "") return; 53 | 54 | Assert.Throws(() => new SchemaObject(sql)); 55 | } 56 | #endregion 57 | 58 | #region Schema Tests 59 | /// 60 | /// Test that when everything after the last GO is a comment or whitespace, the last section is ignored. 61 | /// UNLESS it's an autoproc, which can be embedded in comments. 62 | /// 63 | [Test] 64 | public void TestTrailingWhiteSpaceAndComments() 65 | { 66 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1"); 67 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO "); 68 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO \n"); 69 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO \n \n"); 70 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO --comment"); 71 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO \n --comment"); 72 | AssertScriptCount(1, "CREATE PROC Foo AS SELECT 1 \n GO \n --comment \n"); 73 | AssertScriptCount(2, "CREATE PROC Foo AS SELECT 1 \n GO \n --comment \n CREATE PROC Goo AS SELECT 1 \n GO"); 74 | 75 | // autoprocs are purely comment-based, so we need to make sure they work 76 | AssertScriptCount(1, "-- AUTOPROC Beer All"); 77 | AssertScriptCount(2, "-- AUTOPROC Beer All \n GO \n -- AUTOPROC Glasses All"); 78 | AssertScriptCount(2, "CREATE PROC Foo AS SELECT 1 \n GO \n -- AUTOPROC Beer All"); 79 | AssertScriptCount(2, "CREATE PROC Foo AS SELECT 1 \n GO \n -- AUTOPROC Beer All"); 80 | } 81 | 82 | private void AssertScriptCount(int count, string sql) 83 | { 84 | StringReader reader = new StringReader(sql); 85 | SchemaObjectCollection c = new SchemaObjectCollection(); 86 | c.Load(reader); 87 | Assert.AreEqual(count, c.Count); 88 | } 89 | #endregion 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Tests/Insight.Database.Schema.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336} 8 | Library 9 | Properties 10 | Insight.Database.Schema.Tests 11 | Insight.Database.Schema.Tests 12 | v4.5 13 | 512 14 | ..\ 15 | true 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll 37 | 38 | 39 | ..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | Always 64 | 65 | 66 | 67 | 68 | 69 | {fbd1c65f-9054-42c7-ba0e-48a922c4c747} 70 | Insight.Database.Schema 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaEventLogger.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Globalization; 6 | using System.Text; 7 | 8 | using Insight.Database.Schema.Properties; 9 | #endregion 10 | 11 | namespace Insight.Database.Schema 12 | { 13 | #region SchemaEventLogger Class 14 | /// 15 | /// Logs events from a schema installer. 16 | /// 17 | public abstract class SchemaEventLogger 18 | { 19 | #region Constructors 20 | /// 21 | /// Construct an event logger 22 | /// 23 | protected SchemaEventLogger () 24 | { 25 | _onSchemaChange = new EventHandler (OnSchemaChange); 26 | } 27 | 28 | /// 29 | /// Construct an event logger and attach it to a schema installer. 30 | /// 31 | /// The installer to monitor 32 | protected SchemaEventLogger (SchemaInstaller installer) : this() 33 | { 34 | Attach (installer); 35 | } 36 | #endregion 37 | 38 | #region Attach/Detach Methods 39 | /// 40 | /// Attach to the events of a SchemaInstaller 41 | /// 42 | /// The installer to attach to 43 | public void Attach (SchemaInstaller installer) 44 | { 45 | if (installer == null) throw new ArgumentNullException("installer"); 46 | 47 | installer.DroppingObject += _onSchemaChange; 48 | installer.CreatingObject += _onSchemaChange; 49 | installer.CreatedObject += _onSchemaChange; 50 | installer.DropFailed += _onSchemaChange; 51 | } 52 | 53 | /// 54 | /// Detach from the events of a SchemaInstaller 55 | /// 56 | /// The installer to detach from 57 | public void Detach (SchemaInstaller installer) 58 | { 59 | if (installer == null) throw new ArgumentNullException("installer"); 60 | 61 | installer.DroppingObject -= _onSchemaChange; 62 | installer.CreatingObject -= _onSchemaChange; 63 | installer.CreatedObject -= _onSchemaChange; 64 | installer.DropFailed -= _onSchemaChange; 65 | } 66 | 67 | private EventHandler _onSchemaChange; 68 | #endregion 69 | 70 | #region Event Handlers 71 | /// 72 | /// Called when a schema event is received 73 | /// 74 | /// The schema event 75 | public abstract void LogSchemaChange (SchemaEventArgs se); 76 | 77 | private void OnSchemaChange (object sender, SchemaEventArgs se) 78 | { 79 | LogSchemaChange (se); 80 | } 81 | #endregion 82 | 83 | #region Support Methods 84 | /// 85 | /// Format a schema event into a string 86 | /// 87 | /// The schema event to format 88 | /// The formatted event 89 | protected static string FormatEventArgs (SchemaEventArgs se) 90 | { 91 | if (se == null) throw new ArgumentNullException("se"); 92 | 93 | string eventName; 94 | switch (se.EventType) 95 | { 96 | case SchemaEventType.BeforeDrop: 97 | eventName = Resources.Dropping; 98 | break; 99 | case SchemaEventType.BeforeCreate: 100 | eventName = Resources.Creating; 101 | break; 102 | case SchemaEventType.AfterCreate: 103 | eventName = Resources.Created; 104 | break; 105 | case SchemaEventType.DropFailed: 106 | return String.Format(CultureInfo.CurrentCulture, "Drop Failed: {0} {1}", se.ObjectName, se.Exception.Message); 107 | 108 | default: 109 | eventName = Enum.Format (typeof (SchemaEventType), se.EventType, "G"); 110 | break; 111 | } 112 | 113 | return String.Format (CultureInfo.CurrentCulture, "{0} {1}", eventName, se.ObjectName); 114 | } 115 | #endregion 116 | } 117 | #endregion 118 | } 119 | -------------------------------------------------------------------------------- /Insight.Database.Schema.Verifier/Insight.Database.Schema.Verifier.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA} 8 | Exe 9 | Properties 10 | Insight.Database.Schema.Verifier 11 | Insight.Database.Schema.Verifier 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | False 37 | ..\..\..\..\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll 38 | 39 | 40 | False 41 | ..\..\..\..\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.Management.Sdk.Sfc.dll 42 | 43 | 44 | False 45 | ..\..\..\..\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.Smo.dll 46 | 47 | 48 | False 49 | ..\..\..\..\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.SmoExtended.dll 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {fbd1c65f-9054-42c7-ba0e-48a922c4c747} 69 | Insight.Database.Schema 70 | 71 | 72 | 73 | 80 | -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/Permission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | class Permission : SchemaImpl 12 | { 13 | public Permission(string name, string sql) : base(name, sql, 1) 14 | { 15 | } 16 | 17 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] 18 | public override bool Exists(IDbConnection connection) 19 | { 20 | // check permissions by querying the permissions table 21 | Match m = Regex.Match(Name.Original, String.Format(CultureInfo.InvariantCulture, @"(?\w+)\s+ON\s+(?{0})\s+TO\s+(?{0})", SqlParser.SqlNameExpression)); 22 | 23 | var userName = new SqlName(m.Groups["user"].Value, 1); 24 | var objectName = new SqlName(m.Groups["object"].Value, 2); 25 | 26 | var permissions = connection.QuerySql(@"SELECT PermissionName=p.permission_name, ObjectType=ISNULL(o.type_desc, p.class_desc) 27 | FROM sys.database_principals u 28 | JOIN sys.database_permissions p ON (u.principal_id = p.grantee_principal_id) 29 | LEFT JOIN sys.objects o ON (p.class_desc = 'OBJECT_OR_COLUMN' AND p.major_id = o.object_id) 30 | LEFT JOIN sys.schemas os ON (o.schema_id = os.schema_id AND os.name = @SchemaName) 31 | LEFT JOIN sys.types t ON (p.class_desc = 'TYPE' AND p.major_id = t.user_type_id) 32 | LEFT JOIN sys.schemas s ON (p.class_desc = 'SCHEMA' AND p.major_id = s.schema_id) 33 | WHERE state_desc IN ('GRANT', 'GRANT_WITH_GRANT_OPTION') 34 | AND u.name = @UserName 35 | AND COALESCE(o.name, t.name, s.name) = @ObjectName", 36 | new Dictionary() 37 | { 38 | { "UserName", userName.Object }, 39 | { "SchemaName", objectName.Schema }, 40 | { "ObjectName", objectName.Object } 41 | }); 42 | 43 | string type = permissions.Select((dynamic p) => p.ObjectType).FirstOrDefault(); 44 | string permission = m.Groups["permission"].Value.ToUpperInvariant(); 45 | 46 | switch (permission) 47 | { 48 | case "EXEC": 49 | return permissions.Any((dynamic p) => p.PermissionName == "EXECUTE"); 50 | 51 | case "ALL": 52 | switch (type) 53 | { 54 | case null: 55 | // this happens on initial install when there is no database 56 | return false; 57 | 58 | case "SQL_STORED_PROCEDURE": 59 | return permissions.Any((dynamic p) => p.PermissionName == "EXECUTE"); 60 | 61 | case "SQL_SCALAR_FUNCTION": 62 | return permissions.Any((dynamic p) => p.PermissionName == "EXECUTE") && 63 | permissions.Any((dynamic p) => p.PermissionName == "REFERENCES"); 64 | 65 | case "SQL_INLINE_TABLE_VALUED_FUNCTION": 66 | case "SQL_TABLE_VALUED_FUNCTION": 67 | case "USER_TABLE": 68 | case "VIEW": 69 | return permissions.Any((dynamic p) => p.PermissionName == "REFERENCES") && 70 | permissions.Any((dynamic p) => p.PermissionName == "SELECT") && 71 | permissions.Any((dynamic p) => p.PermissionName == "INSERT") && 72 | permissions.Any((dynamic p) => p.PermissionName == "UPDATE") && 73 | permissions.Any((dynamic p) => p.PermissionName == "DELETE"); 74 | 75 | case "DATABASE": 76 | return permissions.Any((dynamic p) => p.PermissionName == "BACKUP DATABASE") && 77 | permissions.Any((dynamic p) => p.PermissionName == "BACKUP LOG") && 78 | permissions.Any((dynamic p) => p.PermissionName == "CREATE DATABASE") && 79 | permissions.Any((dynamic p) => p.PermissionName == "CREATE DEFAULT") && 80 | permissions.Any((dynamic p) => p.PermissionName == "CREATE FUNCTION") && 81 | permissions.Any((dynamic p) => p.PermissionName == "CREATE PROCEDURE") && 82 | permissions.Any((dynamic p) => p.PermissionName == "CREATE RULE") && 83 | permissions.Any((dynamic p) => p.PermissionName == "CREATE TABLE") && 84 | permissions.Any((dynamic p) => p.PermissionName == "CREATE VIEW"); 85 | 86 | default: 87 | throw new SchemaException(String.Format(CultureInfo.InvariantCulture, "GRANT ALL is not supported for {0} objects", type)); 88 | } 89 | 90 | default: 91 | return permissions.Any((dynamic p) => p.PermissionName == permission); 92 | } 93 | } 94 | 95 | public override void Drop(IDbConnection connection) 96 | { 97 | connection.ExecuteSql(String.Format(@"REVOKE {0}", Name.Original)); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Insight.Database.Schema # 2 | 3 | **Insight.Database.Schema** is a dead-simple easy to use SQL Server database script installer and "SQL code migrator". 4 | 5 | - You write SQL schemas in SQL. 6 | - You *don't* write schema change scripts. 7 | - Insight will automatically calcualte the differences and apply them. 8 | - Great for distributed development of SQL, since you don't have to worry about writing any upgrade code. 9 | 10 | # Why You Want This # 11 | - It just works. 12 | - Without a lot of effort or configuration. 13 | - It gets out of your way. 14 | - SQL is SQL, not some mangled C# form of your data model. 15 | - Works awesome with [Insight.Database](https://github.com/jonwagner/Insight.Database)! 16 | 17 | ## v2.0 Release ## 18 | Huzzah! v2.0 is finally done! 19 | 20 | Why is 2.0 better? 21 | 22 | - Compatibility with SQL Azure, so you can deploy to the cloud. 23 | - No dependency on SQL-SMO - SMO didn't play nicely with SQL Azure. 24 | - Better dependency detection - when you modify something, it makes the minimum set of changes to the database. 25 | - Column-level table updates - now columns can be added, removed, or modified without copying the entire data table. 26 | 27 | Also... 28 | 29 | - The code is a lot cleaner. 30 | - More test cases. 31 | 32 | # Documentation # 33 | 34 | **See the [wiki](https://github.com/jonwagner/Insight.Database.Schema/wiki)!** 35 | 36 | # Some Examples # 37 | 38 | You can read these to get a flavor for the beer/code. But you should go over to the **[wiki](https://github.com/jonwagner/Insight.Database.Schema/wiki).** 39 | 40 | ## Getting Started ## 41 | 1. Get the nuGet package: [http://www.nuget.org/packages/Insight.Database.Schema](http://www.nuget.org/packages/Insight.Database.Schema) 42 | 1. Put your SQL code in SQL files. 43 | 1. Add the SQL files to your project as embedded resources. 44 | 1. Run the installer code (only a few lines below!). 45 | 1. Modify your SQL as needed. 46 | 1. Run the installer to automatically update your database. 47 | 48 | ## Make your SQL ## 49 | 50 | So assume you have Beer.sql: 51 | 52 | CREATE TABLE Beer 53 | ( 54 | [ID] [int] IDENTITY, 55 | [Name] [varchar](128) 56 | ) 57 | GO 58 | CREATE PROC InsertBeer (@Name [varchar](128)) AS 59 | INSERT INTO Beer (Name) 60 | OUTPUT Inserted.ID VALUES (@Name) 61 | GO 62 | 63 | ## Load the Schema in your Setup code and Install it ## 64 | 65 | Only a little code is needed to deploy your SQL. 66 | 67 | // load your SQL into a SchemaObjectCOllection 68 | SchemaObjectCollection schema = new SchemaObjectCollection(); 69 | schema.Load("Beer.sql"); 70 | 71 | // automatically create the database 72 | SchemaInstaller.CreateDatabase(connectionString); 73 | 74 | // automatically install it, or upgrade it 75 | using (SqlConnection connection = new SqlConnection (connectionString)) 76 | { 77 | connection.Open(); 78 | SchemaInstaller installer = new SchemaInstaller(connection); 79 | new SchemaEventConsoleLogger().Attach(installer); 80 | installer.Install("BeerGarten", schema); 81 | } 82 | 83 | ## Make some changes to your SQL ## 84 | 85 | Go ahead. Just modify the SQL. Don't worry about writing upgrade scripts. 86 | 87 | CREATE TABLE Beer 88 | ( 89 | [ID] [int] IDENTITY NOT NULL, 90 | [Name] [varchar](128) NOT NULL, 91 | [Description] [varchar](MAX) 92 | ) 93 | GO 94 | CREATE PROC InsertBeer (@Name [varchar](128), @Description [varchar](MAX)) AS 95 | INSERT INTO Beer (Name, Description) 96 | OUTPUT Inserted.ID VALUES (@Name, @Description) 97 | GO 98 | 99 | Now, run your setup program again. Insight will automatically calculate the differences between the existing database and your new database. Then it will only make the changes necessary to update your database. 100 | 101 | ## Get AutoProcs for Free ## 102 | 103 | Automatically generate standard stored procedures for your tables and have them updated automatically if you change your schema. 104 | 105 | Get all of these for FREE! Select, Insert, Update, Upsert, Delete, SelectMany, InsertMany, UpdateMany, UpsertMany, DeleteMany, Find. 106 | 107 | -- automatically generates Select/Insert/Update/Delete/Find and more 108 | -- AUTOPROC All [Beer] 109 | GO 110 | 111 | ## Use Insight.Database to Access Your Data ## 112 | 113 | You don't have to use Insight.Database if you don't want to, but it's easy and fast. 114 | 115 | To call your stored procedures (and SQL) easily. Use [Insight.Database](https://github.com/jonwagner/Insight.Database)! 116 | It can even automatically generate a repository for all of the AutoProcs. You can select objects and send them back to the database with almost no effort! -------------------------------------------------------------------------------- /Insight.Database.Schema/Implementation/SchemaImpl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Insight.Database.Schema.Implementation 10 | { 11 | abstract class SchemaImpl 12 | { 13 | /// 14 | /// Determines how to split a GO statement in a batch. 15 | /// 16 | protected static Regex _goSplit = new Regex(@"^\s*GO\s*$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Multiline); 17 | 18 | public SqlName Name { get; private set; } 19 | public string Sql { get; private set; } 20 | 21 | public SchemaImpl(string name, string sql, int expectedPartsInName) 22 | { 23 | Name = new SqlName(name, expectedPartsInName); 24 | Sql = sql; 25 | } 26 | 27 | public virtual void Install(IDbConnection connection, IEnumerable objects) 28 | { 29 | try 30 | { 31 | foreach (string s in _goSplit.Split(Sql).Where(piece => !String.IsNullOrWhiteSpace(piece))) 32 | connection.ExecuteSql(s); 33 | } 34 | catch (Exception e) 35 | { 36 | throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot create SQL object {0}: {1}", Name.FullName, e.Message), e); 37 | } 38 | } 39 | 40 | public virtual bool CanDrop(SchemaInstaller.InstallContext context, IDbConnection connection) 41 | { 42 | return true; 43 | } 44 | 45 | public virtual bool CanModify(SchemaInstaller.InstallContext context, IDbConnection connection) 46 | { 47 | return CanDrop(context, connection); 48 | } 49 | 50 | public abstract void Drop(IDbConnection connection); 51 | public abstract bool Exists(IDbConnection connection); 52 | 53 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] 54 | public static SchemaImpl GetImplementation(SchemaObjectType type, string name, string sql) 55 | { 56 | switch (type) 57 | { 58 | case SchemaObjectType.AutoProc: 59 | return new AutoProc(name, sql); 60 | case SchemaObjectType.BrokerPriority: 61 | return new BrokerPriority(name, sql); 62 | case SchemaObjectType.Certificate: 63 | return new Certificate(name, sql); 64 | case SchemaObjectType.Contract: 65 | return new Contract(name, sql); 66 | case SchemaObjectType.Constraint: 67 | return new Constraint(name, sql); 68 | case SchemaObjectType.Default: 69 | return new Default(name, sql); 70 | case SchemaObjectType.Index: 71 | return new Index(name, sql); 72 | case SchemaObjectType.ForeignKey: 73 | return new Constraint(name, sql); 74 | case SchemaObjectType.Function: 75 | return new Function(name, sql); 76 | case SchemaObjectType.IndexedView: 77 | return new View(name, sql); 78 | case SchemaObjectType.Login: 79 | return new Login(name, sql); 80 | case SchemaObjectType.MasterKey: 81 | return new MasterKey(name, sql); 82 | case SchemaObjectType.MessageType: 83 | return new MessageType(name, sql); 84 | case SchemaObjectType.PartitionFunction: 85 | return new PartitionFunction(name, sql); 86 | case SchemaObjectType.PartitionScheme: 87 | return new PartitionScheme(name, sql); 88 | case SchemaObjectType.Permission: 89 | return new Permission(name, sql); 90 | case SchemaObjectType.PrimaryKey: 91 | return new PrimaryKey(name, sql); 92 | case SchemaObjectType.PrimaryXmlIndex: 93 | return new Index(name, sql); 94 | case SchemaObjectType.Queue: 95 | return new Queue(name, sql); 96 | case SchemaObjectType.Role: 97 | return new Role(name, sql); 98 | case SchemaObjectType.Schema: 99 | return new Schema(name, sql); 100 | case SchemaObjectType.SecondaryXmlIndex: 101 | return new Index(name, sql); 102 | case SchemaObjectType.Service: 103 | return new Service(name, sql); 104 | case SchemaObjectType.StoredProcedure: 105 | return new StoredProcedure(name, sql); 106 | case SchemaObjectType.Table: 107 | return new Table(name, sql); 108 | case SchemaObjectType.Trigger: 109 | return new Trigger(name, sql); 110 | case SchemaObjectType.User: 111 | return new User(name, sql); 112 | case SchemaObjectType.UserDefinedType: 113 | return new UserDefinedType(name, sql); 114 | case SchemaObjectType.View: 115 | return new View(name, sql); 116 | 117 | 118 | case SchemaObjectType.UserPreScript: 119 | case SchemaObjectType.Unused: 120 | case SchemaObjectType.Script: 121 | case SchemaObjectType.UserScript: 122 | return new Script(name, sql); 123 | 124 | default: 125 | return null; 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Insight.Database.Schema/RecordingDbCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.Common; 5 | using System.Data.SqlClient; 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Insight.Database.Schema 12 | { 13 | /// 14 | /// Wraps an IDbCommand and allows the commands to be recorded. 15 | /// 16 | class RecordingDbCommand : DbCommand 17 | { 18 | #region Private Members 19 | /// 20 | /// Gets the inner command to use to execute the command. 21 | /// 22 | private DbCommand InnerCommand { get; set; } 23 | 24 | /// 25 | /// The recording connection we are associated with. 26 | /// 27 | private RecordingDbConnection RecordingConnection { get; set; } 28 | #endregion 29 | 30 | #region Constructors 31 | /// 32 | /// Initializes a new instance of the ReliableCommand class, and bind it to the specified ReliableConnection and innerCommand. 33 | /// 34 | /// The retry strategy to use for the command. 35 | /// The innerCommand to bind to. 36 | public RecordingDbCommand(DbCommand innerCommand, RecordingDbConnection recordingConnection) 37 | { 38 | if (innerCommand is RecordingDbCommand) 39 | throw new InvalidOperationException("Cannot record from within a RecordingDbCommand"); 40 | 41 | InnerCommand = innerCommand; 42 | RecordingConnection = recordingConnection; 43 | } 44 | #endregion 45 | 46 | #region Synchronous DbCommand Implementation 47 | public override int ExecuteNonQuery() 48 | { 49 | RecordingConnection.LogCommand(CommandText); 50 | 51 | if (!RecordingConnection.CanExecute) 52 | return 0; 53 | 54 | return InnerCommand.ExecuteNonQuery(); 55 | } 56 | 57 | protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) 58 | { 59 | RecordingConnection.LogCommand(CommandText); 60 | 61 | if (!RecordingConnection.CanExecute) 62 | return null; 63 | 64 | return InnerCommand.ExecuteReader(behavior); 65 | } 66 | 67 | public override object ExecuteScalar() 68 | { 69 | RecordingConnection.LogCommand(CommandText); 70 | 71 | if (!RecordingConnection.CanExecute) 72 | return null; 73 | 74 | return InnerCommand.ExecuteScalar(); 75 | } 76 | #endregion 77 | 78 | #region Support Methods 79 | public override void Prepare() 80 | { 81 | InnerCommand.Prepare(); 82 | } 83 | #endregion 84 | 85 | #region IDbCommand Implementation 86 | public override void Cancel() 87 | { 88 | InnerCommand.Cancel(); 89 | } 90 | 91 | public override string CommandText 92 | { 93 | get 94 | { 95 | return InnerCommand.CommandText; 96 | } 97 | 98 | set 99 | { 100 | InnerCommand.CommandText = value; 101 | } 102 | } 103 | 104 | public override int CommandTimeout 105 | { 106 | get 107 | { 108 | return InnerCommand.CommandTimeout; 109 | } 110 | 111 | set 112 | { 113 | InnerCommand.CommandTimeout = value; 114 | } 115 | } 116 | 117 | public override CommandType CommandType 118 | { 119 | get 120 | { 121 | return InnerCommand.CommandType; 122 | } 123 | 124 | set 125 | { 126 | InnerCommand.CommandType = value; 127 | } 128 | } 129 | 130 | protected override DbConnection DbConnection 131 | { 132 | get 133 | { 134 | return InnerCommand.Connection; 135 | } 136 | 137 | set 138 | { 139 | InnerCommand.Connection = value.Unwrap(); 140 | } 141 | } 142 | 143 | protected override DbParameter CreateDbParameter() 144 | { 145 | return InnerCommand.CreateParameter(); 146 | } 147 | 148 | protected override DbParameterCollection DbParameterCollection 149 | { 150 | get { return InnerCommand.Parameters; } 151 | } 152 | 153 | protected override DbTransaction DbTransaction 154 | { 155 | get 156 | { 157 | return InnerCommand.Transaction; 158 | } 159 | 160 | set 161 | { 162 | InnerCommand.Transaction = value; 163 | } 164 | } 165 | 166 | public override UpdateRowSource UpdatedRowSource 167 | { 168 | get 169 | { 170 | return InnerCommand.UpdatedRowSource; 171 | } 172 | 173 | set 174 | { 175 | InnerCommand.UpdatedRowSource = value; 176 | } 177 | } 178 | 179 | public override bool DesignTimeVisible 180 | { 181 | get 182 | { 183 | return InnerCommand.DesignTimeVisible; 184 | } 185 | 186 | set 187 | { 188 | InnerCommand.DesignTimeVisible = value; 189 | } 190 | } 191 | #endregion 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SqlColumnDefinitionProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Data.SqlClient; 5 | using System.Globalization; 6 | using System.Linq; 7 | using System.Text; 8 | using Insight.Database; 9 | 10 | namespace Insight.Database.Schema 11 | { 12 | /// 13 | /// Provides information about the columns in a SQL Server table. 14 | /// 15 | class SqlColumnDefinitionProvider : IColumnDefinitionProvider 16 | { 17 | /// 18 | /// The connection to use to connect to the database. 19 | /// 20 | private IDbConnection _connection; 21 | 22 | /// 23 | /// Initializes an instance of a SqlColumnDefinitionProvider. 24 | /// 25 | /// The connection to the database. 26 | public SqlColumnDefinitionProvider(IDbConnection connection) 27 | { 28 | _connection = connection; 29 | } 30 | 31 | /// 32 | /// Return the column definitions for a table. 33 | /// 34 | /// The name of the table. 35 | /// The definitions of the columns in the table. 36 | public IList GetColumns(SqlName tableName) 37 | { 38 | List columns = new List(); 39 | 40 | // get the schema of the table and the primary key 41 | string schemaSql = String.Format(CultureInfo.InvariantCulture, @" 42 | SELECT c.name, type_name=t.name, c.max_length, c.precision, c.scale, is_identity, is_readonly = is_identity | is_computed, c.is_nullable, 43 | is_key = CASE WHEN pk.column_id IS NOT NULL THEN 1 ELSE 0 END, 44 | has_default = CASE WHEN c.default_object_id <> 0 THEN 1 ELSE 0 END 45 | FROM sys.columns c 46 | JOIN sys.types t ON (c.user_type_id = t.user_type_id AND t.is_user_defined = 0) 47 | LEFT JOIN ( 48 | SELECT ic.object_id, ic.column_id 49 | FROM sys.index_columns ic 50 | JOIN sys.indexes i ON (ic.object_id = i.object_id AND ic.index_id = i.index_id) 51 | WHERE i.is_primary_key = 1 52 | ) AS pk ON (c.object_id = pk.object_id AND c.column_id = pk.column_id) 53 | WHERE c.object_id = OBJECT_ID('{0}') 54 | ", tableName.SchemaQualifiedTable); 55 | 56 | using (IDataReader reader = _connection.GetReaderSql(schemaSql)) 57 | { 58 | while (reader.Read()) 59 | { 60 | ColumnDefinition column = new ColumnDefinition() 61 | { 62 | Name = reader["name"].ToString(), 63 | SqlType = reader["type_name"].ToString(), 64 | 65 | IsKey = Convert.ToBoolean(reader["is_key"], CultureInfo.InvariantCulture), 66 | IsIdentity = Convert.ToBoolean(reader["is_identity"], CultureInfo.InvariantCulture), 67 | IsReadOnly = Convert.ToBoolean(reader["is_readonly"], CultureInfo.InvariantCulture), 68 | IsUpdateNullable = Convert.ToBoolean(reader["is_nullable"], CultureInfo.InvariantCulture), 69 | HasDefault = Convert.ToBoolean(reader["has_default"], CultureInfo.InvariantCulture), 70 | }; 71 | 72 | switch (column.SqlType) 73 | { 74 | case "char": 75 | case "nchar": 76 | case "varchar": 77 | case "nvarchar": 78 | case "binary": 79 | case "varbinary": 80 | column.SqlType += String.Format(CultureInfo.InvariantCulture, "({0})", GetColumnLength(column.SqlType, Int32.Parse(reader["max_length"].ToString(), CultureInfo.InvariantCulture))); 81 | break; 82 | 83 | case "decimal": 84 | case "numeric": 85 | column.SqlType += String.Format(CultureInfo.InvariantCulture, "({0}, {1})", reader["precision"].ToString(), reader["scale"].ToString()); 86 | break; 87 | 88 | case "float": 89 | column.SqlType += String.Format(CultureInfo.InvariantCulture, "({0})", reader["precision"].ToString()); 90 | break; 91 | 92 | case "real": 93 | break; 94 | 95 | case "rowversion": 96 | case "timestamp": 97 | column.IsReadOnly = true; 98 | column.IsRowVersion = true; 99 | column.IsUpdateNullable = true; 100 | break; 101 | } 102 | 103 | columns.Add(column); 104 | } 105 | } 106 | 107 | return columns; 108 | } 109 | 110 | /// 111 | /// Calculate the column length based on the max_length field in SQL Server. 112 | /// 113 | /// The type of the column 114 | /// The length in the sys.columns table. 115 | /// The length to use for scripting. 116 | internal static string GetColumnLength(string sqlType, int maxLength) 117 | { 118 | if (maxLength == -1) 119 | return "MAX"; 120 | 121 | if (sqlType == "nchar" || sqlType == "nvarchar") 122 | maxLength /= 2; 123 | 124 | return maxLength.ToString(CultureInfo.InvariantCulture); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Insight.Database.Schema/SchemaObjectType.cs: -------------------------------------------------------------------------------- 1 | #region Using directives 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | #endregion 9 | 10 | namespace Insight.Database.Schema 11 | { 12 | #region SchemaObjectType Enumeration 13 | /// 14 | /// The type of a database object 15 | /// 16 | /// These are in the order that objects need to be created 17 | public enum SchemaObjectType 18 | { 19 | /// 20 | /// A user script that needs to run first 21 | /// 22 | [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PreScript", Justification="This field value is stored in databases")] 23 | UserPreScript, 24 | 25 | /// 26 | /// A SQL Server 2005 ROLE 27 | /// 28 | Role, 29 | 30 | /// 31 | /// A SQL Server 2005 SCHEMA 32 | /// 33 | Schema, 34 | 35 | /// 36 | /// A user defined type 37 | /// 38 | UserDefinedType, 39 | 40 | /// 41 | /// A database master key 42 | /// 43 | MasterKey, 44 | 45 | /// 46 | /// A certificate 47 | /// 48 | Certificate, 49 | 50 | /// 51 | /// A symmetric key 52 | /// 53 | SymmetricKey, 54 | 55 | /// 56 | /// A partition function 57 | /// 58 | PartitionFunction, 59 | 60 | /// 61 | /// A partition scheme 62 | /// 63 | PartitionScheme, 64 | 65 | /// 66 | /// Service Broker Message Type 67 | /// 68 | MessageType, 69 | 70 | /// 71 | /// Service Broker Contract 72 | /// 73 | Contract, 74 | 75 | /// 76 | /// Service Broker Priority 77 | /// 78 | BrokerPriority, 79 | 80 | /// 81 | /// Service Broker Queue 82 | /// 83 | Queue, 84 | 85 | /// 86 | /// Service Broker Service 87 | /// 88 | Service, 89 | 90 | /// 91 | /// A table in the database 92 | /// 93 | Table, 94 | 95 | /// 96 | /// A default in the database 97 | /// 98 | Default, 99 | 100 | /// 101 | /// A primary key on a table 102 | /// 103 | PrimaryKey, 104 | 105 | /// 106 | /// Automatically generated Select, Insert, Update, Delete 107 | /// 108 | AutoProc, 109 | 110 | /// 111 | /// A constraint on a table 112 | /// 113 | Constraint, 114 | 115 | /// 116 | /// A foreign key constraint 117 | /// 118 | ForeignKey, 119 | 120 | /// 121 | /// A user defined function 122 | /// 123 | Function, 124 | 125 | /// 126 | /// An indexed view is marked so that insight won't drop it on a procedure change 127 | /// 128 | IndexedView, 129 | 130 | /// 131 | /// An index 132 | /// 133 | Index, 134 | 135 | /// 136 | /// A view on one or more tables 137 | /// 138 | View, 139 | 140 | /// 141 | /// The primary XML Index on a column 142 | /// 143 | PrimaryXmlIndex, 144 | 145 | /// 146 | /// A secondary XML Index on a column 147 | /// 148 | SecondaryXmlIndex, 149 | 150 | /// 151 | /// A stored procedure 152 | /// 153 | StoredProcedure, 154 | 155 | /// 156 | /// A login to the server 157 | /// 158 | [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login")] 159 | Login, 160 | 161 | /// 162 | /// A user in the database 163 | /// 164 | User, 165 | 166 | /// 167 | /// Permission script 168 | /// 169 | Permission, 170 | 171 | /// 172 | /// A table trigger 173 | /// 174 | Trigger, 175 | 176 | /// 177 | /// General padding things added by SQL Server scripter like SET ANSI NULLS ON 178 | /// 179 | Unused, 180 | 181 | /// 182 | /// Objects that were scripted by the dependency generator, or just need to be run by the user 183 | /// 184 | Script, 185 | 186 | /// 187 | /// A script object that just runs when it changes 188 | /// 189 | UserScript, 190 | 191 | /// 192 | /// An object that contains SQL that we don't support. 193 | /// 194 | Unsupported 195 | } 196 | #endregion 197 | } 198 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /TestSchema.sql: -------------------------------------------------------------------------------- 1 | CREATE SCHEMA foo 2 | GO 3 | 4 | CREATE ROLE MyRole 5 | GO 6 | 7 | CREATE LOGIN [TestLogin] WITH PASSWORD='test' 8 | GO 9 | 10 | CREATE USER [User] WITHOUT LOGIN 11 | GO 12 | 13 | -- PRESCRIPT [MyPreScript] 14 | PRINT 'hello' 15 | GO 16 | 17 | -- SCRIPT [MyScript] 18 | PRINT 'hello' 19 | GO 20 | 21 | CREATE MASTER KEY 22 | ENCRYPTION BY PASSWORD = 'pGFD4bb925DGvbd2439587y' 23 | GO 24 | 25 | CREATE CERTIFICATE [Certificate] 26 | ENCRYPTION BY PASSWORD = 'pGFD4bb925DGvbd2439587y' 27 | WITH SUBJECT = 'Sammamish Shipping Records', 28 | EXPIRY_DATE = '20221031'; 29 | GO 30 | 31 | CREATE BROKER PRIORITY [TestPriority] FOR CONVERSATION 32 | GO 33 | 34 | CREATE MESSAGE TYPE [//Test/TestMessage] 35 | VALIDATION = WELL_FORMED_XML 36 | GO 37 | 38 | CREATE CONTRACT [Contract] ( 39 | [//Test/TestMessage] SENT BY INITIATOR 40 | ); 41 | GO 42 | 43 | CREATE QUEUE [Queue] 44 | GO 45 | 46 | CREATE SERVICE [Service] ON QUEUE [Queue] 47 | GO 48 | 49 | CREATE PARTITION FUNCTION PartitionFunction (int) 50 | AS RANGE LEFT 51 | FOR VALUES (1) 52 | GO 53 | 54 | CREATE PARTITION SCHEME PartitionScheme 55 | AS PARTITION PartitionFunction 56 | ALL TO ([PRIMARY]) 57 | GO 58 | 59 | ------------------------------------------------------------------------------------------------------------- 60 | -- things that are a little weird 61 | ------------------------------------------------------------------------------------------------------------- 62 | -- this has a dot in the constraint name 63 | ALTER TABLE [dbo].[Table] ADD CONSTRAINT [CT_Table.Something] CHECK (Data > 'b') 64 | GO 65 | 66 | ------------------------------------------------------------------------------------------------------------- 67 | -- things that can be in a schema 68 | ------------------------------------------------------------------------------------------------------------- 69 | CREATE TYPE [dbo].[MyType] FROM [int] 70 | GO 71 | 72 | CREATE TABLE [dbo].[Table]( 73 | [ID] [int] IDENTITY(1,1) NOT NULL, 74 | [Data] [varchar](100) NOT NULL, 75 | [Xml] [xml], 76 | [MyType] [MyType] 77 | ) 78 | GO 79 | 80 | -- AUTOPROC All [dbo].[Table] 81 | GO 82 | 83 | GRANT SELECT ON [dbo].[Table] TO [MyRole] 84 | GO 85 | 86 | CREATE TABLE [dbo].[Table2]( 87 | [ID] [int] IDENTITY(1,1) NOT NULL, 88 | [ID1] [int] 89 | ) 90 | GO 91 | 92 | CREATE VIEW [dbo].[View] AS 93 | SELECT * FROM [dbo].[Table] 94 | GO 95 | 96 | -- INDEXEDVIEW 97 | CREATE VIEW [dbo].[IndexedView] WITH SCHEMABINDING AS 98 | SELECT ID, Data FROM [dbo].[Table] 99 | GO 100 | 101 | CREATE TRIGGER [dbo].[TRG_Table] ON [dbo].[Table] 102 | FOR INSERT 103 | AS 104 | PRINT 'Inserted' 105 | GO 106 | 107 | CREATE UNIQUE CLUSTERED INDEX [IX_IndexedView] ON [dbo].[IndexedView] (ID) 108 | GO 109 | 110 | ALTER TABLE [dbo].[Table] ADD CONSTRAINT [DF_Data] DEFAULT ((0)) FOR [Data] 111 | GO 112 | 113 | ALTER TABLE [dbo].[Table] ADD CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED ([ID]) 114 | GO 115 | 116 | ALTER TABLE [dbo].[Table2] ADD CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ([ID]) 117 | GO 118 | 119 | ALTER TABLE [dbo].[Table2] ADD CONSTRAINT [FK_Table] FOREIGN KEY ([ID1]) REFERENCES [dbo].[Table] (ID) 120 | GO 121 | 122 | ALTER TABLE [dbo].[Table] ADD CONSTRAINT [CT_Table] CHECK (Data > 'b') 123 | GO 124 | 125 | CREATE INDEX IX_Table ON [dbo].[Table] (Data) 126 | GO 127 | 128 | CREATE PRIMARY XML INDEX IX_Xml ON [dbo].[Table] ([Xml]) 129 | GO 130 | 131 | CREATE XML INDEX IX_Xml2 ON [dbo].[Table] ([Xml]) 132 | USING XML INDEX IX_Xml FOR PATH; 133 | GO 134 | 135 | CREATE PROC [dbo].[Proc] AS 136 | SELECT * FROM [dbo].[Table] 137 | GO 138 | 139 | GRANT EXEC ON [dbo].[Proc] TO [MyRole] 140 | GO 141 | 142 | CREATE FUNCTION [dbo].[Func] () RETURNS INT AS 143 | BEGIN 144 | DECLARE @c [int] 145 | SELECT @c=COUNT(*) FROM [dbo].[Table] 146 | RETURN @c 147 | END 148 | GO 149 | 150 | ------------------------------------------------------------------------------------------------------------- 151 | -- duplicate of above, but with a different schema 152 | ------------------------------------------------------------------------------------------------------------- 153 | CREATE TYPE [foo].[MyType] FROM [int] 154 | GO 155 | 156 | CREATE TABLE [foo].[Table]( 157 | [ID] [int] IDENTITY(1,1) NOT NULL, 158 | [Data] [varchar](100) NOT NULL, 159 | [Xml] [xml], 160 | [MyType] [MyType] 161 | ) 162 | GO 163 | 164 | -- AUTOPROC All [foo].[Table] 165 | GO 166 | 167 | GRANT SELECT ON [foo].[Table] TO [MyRole] 168 | GO 169 | 170 | CREATE TABLE [foo].[Table2]( 171 | [ID] [int] IDENTITY(1,1) NOT NULL, 172 | [ID1] [int] 173 | ) 174 | GO 175 | 176 | CREATE VIEW [foo].[View] AS 177 | SELECT * FROM [foo].[Table] 178 | GO 179 | 180 | -- INDEXEDVIEW 181 | CREATE VIEW [foo].[IndexedView] WITH SCHEMABINDING AS 182 | SELECT ID, Data FROM [foo].[Table] 183 | GO 184 | 185 | CREATE TRIGGER [foo].[TRG_Table] ON [foo].[Table] 186 | FOR INSERT 187 | AS 188 | PRINT 'Inserted' 189 | GO 190 | 191 | CREATE UNIQUE CLUSTERED INDEX [IX_IndexedView] ON [foo].[IndexedView] (ID) 192 | GO 193 | 194 | ALTER TABLE [foo].[Table] ADD CONSTRAINT [DF_Data] DEFAULT ((0)) FOR [Data] 195 | GO 196 | 197 | ALTER TABLE [foo].[Table] ADD CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED ([ID]) 198 | GO 199 | 200 | ALTER TABLE [foo].[Table2] ADD CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ([ID]) 201 | GO 202 | 203 | ALTER TABLE [foo].[Table2] ADD CONSTRAINT [FK_Table] FOREIGN KEY ([ID1]) REFERENCES [foo].[Table] (ID) 204 | GO 205 | 206 | ALTER TABLE [foo].[Table] ADD CONSTRAINT [CT_Table] CHECK (Data > 'b') 207 | GO 208 | 209 | CREATE INDEX IX_Table ON [foo].[Table] (Data) 210 | GO 211 | 212 | CREATE PRIMARY XML INDEX IX_Xml ON [foo].[Table] ([Xml]) 213 | GO 214 | 215 | CREATE XML INDEX IX_Xml2 ON [foo].[Table] ([Xml]) 216 | USING XML INDEX IX_Xml FOR PATH; 217 | GO 218 | 219 | CREATE PROC [foo].[Proc] AS 220 | SELECT * FROM [foo].[Table] 221 | GO 222 | 223 | GRANT EXEC ON [foo].[Proc] TO [MyRole] 224 | GO 225 | 226 | CREATE FUNCTION [foo].[Func] () RETURNS INT AS 227 | BEGIN 228 | DECLARE @c [int] 229 | SELECT @c=COUNT(*) FROM [foo].[Table] 230 | RETURN @c 231 | END 232 | GO 233 | -------------------------------------------------------------------------------- /autobuild.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Release 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | version.txt 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Insight.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CEDD5EAD-7CF5-45EE-8676-EFEC0CBAB552}" 7 | ProjectSection(SolutionItems) = preProject 8 | Build.bat = Build.bat 9 | Build.ps1 = Build.ps1 10 | Build.psake.ps1 = Build.psake.ps1 11 | Building.txt = Building.txt 12 | Insight.Database.Schema.nuspec = Insight.Database.Schema.nuspec 13 | License.txt = License.txt 14 | README.md = README.md 15 | TestSchema.sql = TestSchema.sql 16 | EndProjectSection 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insight.Database.Schema", "Insight.Database.Schema\Insight.Database.Schema.csproj", "{FBD1C65F-9054-42C7-BA0E-48A922C4C747}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insight.Database.Schema.Sample", "Insight.Database.Schema.Sample\Insight.Database.Schema.Sample.csproj", "{C4468859-9F7A-41DF-A6DC-94118F6BAE8D}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insight.Database.Schema.Tests", "Insight.Database.Schema.Tests\Insight.Database.Schema.Tests.csproj", "{AA0C2EDB-9659-418D-BCA4-3CBF16B90336}" 23 | EndProject 24 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insight.Database.Schema.Verifier", "Insight.Database.Schema.Verifier\Insight.Database.Schema.Verifier.csproj", "{1EFC149D-87EA-437F-AA75-3AC1FA178CFA}" 25 | EndProject 26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insight.Database.Schema.Installer", "Insight.Database.Schema.Installer\Insight.Database.Schema.Installer.csproj", "{5873421C-3B4C-478C-84F9-5D64A60E8C5C}" 27 | EndProject 28 | Global 29 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 30 | Debug|Any CPU = Debug|Any CPU 31 | Debug|Mixed Platforms = Debug|Mixed Platforms 32 | Debug|x86 = Debug|x86 33 | Release|Any CPU = Release|Any CPU 34 | Release|Mixed Platforms = Release|Mixed Platforms 35 | Release|x86 = Release|x86 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 41 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 42 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Debug|x86.ActiveCfg = Debug|Any CPU 43 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 46 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Release|Mixed Platforms.Build.0 = Release|Any CPU 47 | {FBD1C65F-9054-42C7-BA0E-48A922C4C747}.Release|x86.ActiveCfg = Release|Any CPU 48 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Debug|Any CPU.ActiveCfg = Debug|x86 49 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 50 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Debug|Mixed Platforms.Build.0 = Debug|x86 51 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Debug|x86.ActiveCfg = Debug|x86 52 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Debug|x86.Build.0 = Debug|x86 53 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Release|Any CPU.ActiveCfg = Release|x86 54 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Release|Mixed Platforms.ActiveCfg = Release|x86 55 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Release|Mixed Platforms.Build.0 = Release|x86 56 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Release|x86.ActiveCfg = Release|x86 57 | {C4468859-9F7A-41DF-A6DC-94118F6BAE8D}.Release|x86.Build.0 = Release|x86 58 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 61 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 62 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Debug|x86.ActiveCfg = Debug|Any CPU 63 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Release|Any CPU.ActiveCfg = Release|Any CPU 64 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Release|Any CPU.Build.0 = Release|Any CPU 65 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 66 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Release|Mixed Platforms.Build.0 = Release|Any CPU 67 | {AA0C2EDB-9659-418D-BCA4-3CBF16B90336}.Release|x86.ActiveCfg = Release|Any CPU 68 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 69 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Debug|Any CPU.Build.0 = Debug|Any CPU 70 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 71 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 72 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Debug|x86.ActiveCfg = Debug|Any CPU 73 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Release|Any CPU.ActiveCfg = Release|Any CPU 74 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Release|Any CPU.Build.0 = Release|Any CPU 75 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 76 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Release|Mixed Platforms.Build.0 = Release|Any CPU 77 | {1EFC149D-87EA-437F-AA75-3AC1FA178CFA}.Release|x86.ActiveCfg = Release|Any CPU 78 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 81 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 82 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Debug|x86.ActiveCfg = Debug|Any CPU 83 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Release|Any CPU.ActiveCfg = Release|Any CPU 84 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Release|Any CPU.Build.0 = Release|Any CPU 85 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 86 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Release|Mixed Platforms.Build.0 = Release|Any CPU 87 | {5873421C-3B4C-478C-84F9-5D64A60E8C5C}.Release|x86.ActiveCfg = Release|Any CPU 88 | EndGlobalSection 89 | GlobalSection(SolutionProperties) = preSolution 90 | HideSolutionNode = FALSE 91 | EndGlobalSection 92 | EndGlobal 93 | --------------------------------------------------------------------------------