diff --git a/docs/project_schema.sql b/docs/project_schema.sql new file mode 100644 index 000000000..b003b9361 --- /dev/null +++ b/docs/project_schema.sql @@ -0,0 +1,93 @@ + + PRAGMA foreign_keys = OFF + + drop table if exists COMMANDS + + drop table if exists COMMAND_PROPERTIES + + drop table if exists DATA_REPOSITORIES + + drop table if exists ENTITIES + + drop table if exists SIMULATIONS + + drop table if exists HISTORY_ITEMS + + drop table if exists CONTENTS + + drop table if exists PROJECTS + + PRAGMA foreign_keys = ON + + create table COMMANDS ( + Id TEXT not null, + CommandId TEXT not null, + Discriminator TEXT not null, + CommandInverseId TEXT, + CommandType TEXT, + ObjectType TEXT, + Description TEXT, + ExtendedDescription TEXT, + Visible INTEGER, + Comment TEXT, + Sequence INTEGER, + ParentId TEXT, + primary key (Id), + constraint FK_DD4B87FE foreign key (ParentId) references COMMANDS + ) + + create table COMMAND_PROPERTIES ( + Id integer primary key autoincrement, + Name TEXT, + Value TEXT, + CommandId TEXT, + constraint FK_71C9276E foreign key (CommandId) references COMMANDS + ) + + create table DATA_REPOSITORIES ( + Id TEXT not null, + ContentId INTEGER, + SimulationId TEXT, + primary key (Id), + constraint fk_DataRepository_Content foreign key (ContentId) references CONTENTS, + constraint FK_524447BC foreign key (SimulationId) references SIMULATIONS + ) + + create table ENTITIES ( + Id TEXT not null, + Discriminator TEXT not null, + ContentId INTEGER, + ProjectId INTEGER, + primary key (Id), + constraint fk_Entity_Content foreign key (ContentId) references CONTENTS, + constraint FK_9F0A793C foreign key (ProjectId) references PROJECTS + ) + + create table SIMULATIONS ( + SimulationId TEXT not null, + primary key (SimulationId), + constraint FK_A2608560 foreign key (SimulationId) references ENTITIES + ) + + create table HISTORY_ITEMS ( + Id TEXT not null, + UserId TEXT, + DateTime TEXT, + State INTEGER, + Sequence INTEGER, + CommandId TEXT, + primary key (Id), + constraint fk_HistoryItem_Command foreign key (CommandId) references COMMANDS + ) + + create table CONTENTS ( + Id integer primary key autoincrement, + Data image + ) + + create table PROJECTS ( + Id integer primary key autoincrement, + Version INTEGER, + ContentId INTEGER, + constraint fk_Project_Content foreign key (ContentId) references CONTENTS + ) diff --git a/src/MoBi.Assets/MoBi.Assets.csproj b/src/MoBi.Assets/MoBi.Assets.csproj index 2dd50ea0d..314f70ce1 100644 --- a/src/MoBi.Assets/MoBi.Assets.csproj +++ b/src/MoBi.Assets/MoBi.Assets.csproj @@ -22,9 +22,9 @@ - - - + + + diff --git a/src/MoBi.BatchTool/MoBi.BatchTool.csproj b/src/MoBi.BatchTool/MoBi.BatchTool.csproj index 2e4bc8d6c..90e5c9237 100644 --- a/src/MoBi.BatchTool/MoBi.BatchTool.csproj +++ b/src/MoBi.BatchTool/MoBi.BatchTool.csproj @@ -49,23 +49,16 @@ - + - + - - - true - false - false - false - \ No newline at end of file diff --git a/src/MoBi.CLI.Core/MoBi.CLI.Core.csproj b/src/MoBi.CLI.Core/MoBi.CLI.Core.csproj index a0b225027..6a3ef925f 100644 --- a/src/MoBi.CLI.Core/MoBi.CLI.Core.csproj +++ b/src/MoBi.CLI.Core/MoBi.CLI.Core.csproj @@ -16,14 +16,14 @@ - - + + - - - - - + + + + + diff --git a/src/MoBi.CLI/MoBi.CLI.csproj b/src/MoBi.CLI/MoBi.CLI.csproj index 9984bc215..199d95c75 100644 --- a/src/MoBi.CLI/MoBi.CLI.csproj +++ b/src/MoBi.CLI/MoBi.CLI.csproj @@ -23,17 +23,16 @@ - - - + + + - - - + + diff --git a/src/MoBi.Core/MoBi.Core.csproj b/src/MoBi.Core/MoBi.Core.csproj index 2797160a1..c0dd7525d 100644 --- a/src/MoBi.Core/MoBi.Core.csproj +++ b/src/MoBi.Core/MoBi.Core.csproj @@ -28,15 +28,17 @@ + - - - - - - - + + + + + + + + diff --git a/src/MoBi.Core/Serialization/ORM/SessionFactoryProvider.cs b/src/MoBi.Core/Serialization/ORM/SessionFactoryProvider.cs index f3cd5f9ae..ad402b020 100644 --- a/src/MoBi.Core/Serialization/ORM/SessionFactoryProvider.cs +++ b/src/MoBi.Core/Serialization/ORM/SessionFactoryProvider.cs @@ -3,13 +3,14 @@ using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; using OSPSuite.Core.Extensions; +using OSPSuite.Infrastructure.Serialization.Extensions; using OSPSuite.Infrastructure.Serialization.Services; namespace MoBi.Core.Serialization.ORM { public class SessionFactoryProvider : ISessionFactoryProvider { - public ISessionFactory InitalizeSessionFactoryFor(string dataSource) + public ISessionFactory InitializeSessionFactoryFor(string dataSource) { var cfg = createSqlLiteConfigurationFor(dataSource); //Create schema for database @@ -20,10 +21,7 @@ public ISessionFactory InitalizeSessionFactoryFor(string dataSource) public ISessionFactory OpenSessionFactoryFor(string dataSource) { - var cfg = createSqlLiteConfigurationFor(dataSource); - var update = new SchemaUpdate(cfg); - update.Execute(useStdOut: false, doUpdate: true); - return cfg.BuildSessionFactory(); + return createSqlLiteConfigurationFor(dataSource).BuildSessionFactory(); } public SchemaExport GetSchemaExport(string dataSource) @@ -38,11 +36,11 @@ private Configuration createSqlLiteConfigurationFor(string dataSource) var configuration = new Configuration(); var path = dataSource.ToUNCPath(); configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); - configuration.SetProperty("connection.driver_class", "NHibernate.Driver.SQLite20Driver"); - configuration.SetProperty("dialect", "NHibernate.Dialect.SQLiteDialect"); + configuration.SetProperty("connection.driver_class", typeof(NHibernate.Extensions.Sqlite.SqliteDriver).AssemblyQualifiedName); + configuration.SetProperty("dialect", typeof(NHibernate.Extensions.Sqlite.SqliteDialect).AssemblyQualifiedName); configuration.SetProperty("query.substitutions", "true=1;false=0"); configuration.SetProperty("show_sql", "false"); - configuration.SetProperty("connection.connection_string", $"Data Source={path};Version=3;New=False;Compress=True;"); + configuration.SetProperty("connection.connection_string", ConnectionStringHelper.ConnectionStringFor(path)); return Fluently.Configure(configuration) .Mappings(cfg => cfg.FluentMappings.AddFromAssemblyOf()).BuildConfiguration(); diff --git a/src/MoBi.Core/Services/ProjectFileCompressor.cs b/src/MoBi.Core/Services/ProjectFileCompressor.cs index f7142a8da..6a24320ea 100644 --- a/src/MoBi.Core/Services/ProjectFileCompressor.cs +++ b/src/MoBi.Core/Services/ProjectFileCompressor.cs @@ -1,6 +1,7 @@ -using System.Data.Common; -using System.Data.SQLite; +using Microsoft.Data.Sqlite; using OSPSuite.Core.Extensions; +using OSPSuite.Infrastructure.Serialization.Extensions; +using System.Data.Common; namespace MoBi.Core.Services { @@ -14,14 +15,14 @@ public class ProjectFileCompressor : IProjectFileCompressor public void Compress(string projectFile) { var path = projectFile.ToUNCPath(); - using (var sqlLite = new SQLiteConnection(string.Format("Data Source={0}", path))) + using (var sqlLite = new SqliteConnection(ConnectionStringHelper.ConnectionStringFor(path))) { sqlLite.Open(); vacuum(sqlLite); } } - private void vacuum(SQLiteConnection sqlLite) + private void vacuum(SqliteConnection sqlLite) { ExecuteNonQuery(sqlLite, "vacuum;"); } diff --git a/src/MoBi.Engine/MoBi.Engine.csproj b/src/MoBi.Engine/MoBi.Engine.csproj index 431419586..462603874 100644 --- a/src/MoBi.Engine/MoBi.Engine.csproj +++ b/src/MoBi.Engine/MoBi.Engine.csproj @@ -28,8 +28,8 @@ - - + + diff --git a/src/MoBi.Presentation/MoBi.Presentation.csproj b/src/MoBi.Presentation/MoBi.Presentation.csproj index ff6fd9547..1200556ce 100644 --- a/src/MoBi.Presentation/MoBi.Presentation.csproj +++ b/src/MoBi.Presentation/MoBi.Presentation.csproj @@ -23,9 +23,9 @@ - - - + + + diff --git a/src/MoBi.R/MoBi.R.csproj b/src/MoBi.R/MoBi.R.csproj index d061191c1..b3bd524db 100644 --- a/src/MoBi.R/MoBi.R.csproj +++ b/src/MoBi.R/MoBi.R.csproj @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/src/MoBi.UI/MoBi.UI.csproj b/src/MoBi.UI/MoBi.UI.csproj index 8d7c35bd3..4c7962c93 100644 --- a/src/MoBi.UI/MoBi.UI.csproj +++ b/src/MoBi.UI/MoBi.UI.csproj @@ -26,11 +26,11 @@ - - - - - + + + + + diff --git a/src/MoBi/MoBi.csproj b/src/MoBi/MoBi.csproj index fbd34e0f6..4362e49ad 100644 --- a/src/MoBi/MoBi.csproj +++ b/src/MoBi/MoBi.csproj @@ -67,15 +67,14 @@ - + - - + + - @@ -84,11 +83,4 @@ - - - true - false - false - false - \ No newline at end of file diff --git a/tests/MoBi.HelpersForTests/DomainHelperForSpecs.cs b/tests/MoBi.HelpersForTests/DomainHelperForSpecs.cs index 45ad95e8d..2cbbfd85e 100644 --- a/tests/MoBi.HelpersForTests/DomainHelperForSpecs.cs +++ b/tests/MoBi.HelpersForTests/DomainHelperForSpecs.cs @@ -17,6 +17,10 @@ public static class DomainHelperForSpecs private static Dimension _concentrationDimension; private static Dimension _timeDimension; + private static readonly string PATH_TO_DOCS = "..\\..\\..\\..\\..\\docs\\"; + + public static string ProjectSchemaDumpFilePath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PATH_TO_DOCS, "project_schema.sql"); + public static string TestFileFullPath(string fileName) { return Path.Combine(TestFileDirectory, fileName); diff --git a/tests/MoBi.HelpersForTests/MoBi.HelpersForTests.csproj b/tests/MoBi.HelpersForTests/MoBi.HelpersForTests.csproj index 70efac741..edc330446 100644 --- a/tests/MoBi.HelpersForTests/MoBi.HelpersForTests.csproj +++ b/tests/MoBi.HelpersForTests/MoBi.HelpersForTests.csproj @@ -6,7 +6,7 @@ - + diff --git a/tests/MoBi.Tests/Core/SessionFactoryProviderHelperForSpecs.cs b/tests/MoBi.Tests/Core/SessionFactoryProviderHelperForSpecs.cs index bba54dded..032b4eb60 100644 --- a/tests/MoBi.Tests/Core/SessionFactoryProviderHelperForSpecs.cs +++ b/tests/MoBi.Tests/Core/SessionFactoryProviderHelperForSpecs.cs @@ -7,7 +7,7 @@ namespace MoBi.Core { public abstract class ContextSpecificationWithSerializationDatabase : ContextSpecification { - private SessionFactoryProvider _sessionFactoryProvider; + protected SessionFactoryProvider _sessionFactoryProvider; protected ISessionFactory _sessionFactory; protected string _dataBaseFile; @@ -17,7 +17,7 @@ public override void GlobalContext() _sessionFactoryProvider = new SessionFactoryProvider(); _dataBaseFile = FileHelper.GenerateTemporaryFileName(); - _sessionFactory = _sessionFactoryProvider.InitalizeSessionFactoryFor(_dataBaseFile); + _sessionFactory = _sessionFactoryProvider.InitializeSessionFactoryFor(_dataBaseFile); } public override void GlobalCleanup() diff --git a/tests/MoBi.Tests/Core/SessionFactoryProviderSpecs.cs b/tests/MoBi.Tests/Core/SessionFactoryProviderSpecs.cs index 772d94a53..09f62fe5c 100644 --- a/tests/MoBi.Tests/Core/SessionFactoryProviderSpecs.cs +++ b/tests/MoBi.Tests/Core/SessionFactoryProviderSpecs.cs @@ -1,10 +1,12 @@ -using OSPSuite.BDDHelper; +using MoBi.Core.Serialization.ORM; using MoBi.Core.Serialization.ORM.MetaData; +using MoBi.HelpersForTests; +using OSPSuite.BDDHelper; using OSPSuite.Infrastructure.Serialization.Services; +using System.IO; namespace MoBi.Core { - public class When_creating_a_session_factory_for_an_existing_given_data_source : ContextSpecificationWithSerializationDatabase { [Observation] @@ -28,4 +30,20 @@ public void should_be_able_to_open_a_session() } } -} \ No newline at end of file + // Dumps the schema of the project database. This makes changes in the schema trackable through version control + public class Comparing_schema_files_for_tracking_purpose : ContextSpecificationWithSerializationDatabase + { + [Observation] + public void should_create_the_database_schema() + { + + var schemaExport = _sessionFactoryProvider.GetSchemaExport(_dataBaseFile); + var directoryName = Path.GetDirectoryName(DomainHelperForSpecs.ProjectSchemaDumpFilePath); + if (!Directory.Exists(directoryName)) + Directory.CreateDirectory(directoryName); + + schemaExport.SetOutputFile(DomainHelperForSpecs.ProjectSchemaDumpFilePath); + schemaExport.Create(true, true); + } + } +} \ No newline at end of file diff --git a/tests/MoBi.Tests/MoBi.Tests.csproj b/tests/MoBi.Tests/MoBi.Tests.csproj index f81c4a93c..d733facdd 100644 --- a/tests/MoBi.Tests/MoBi.Tests.csproj +++ b/tests/MoBi.Tests/MoBi.Tests.csproj @@ -38,13 +38,13 @@ - - - + + + - + @@ -95,11 +95,4 @@ PreserveNewest - - - true - false - false - false - \ No newline at end of file diff --git a/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj b/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj index ae7b427a0..e14415624 100644 --- a/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj +++ b/tests/MoBi.UI.Tests/MoBi.UI.Tests.csproj @@ -19,8 +19,8 @@ - - + +