public void can_write_ddl_by_type_with_schema_creation()
        {
            using (var store = DocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "yet_another";

                _.RegisterDocumentType <Company>();
                _.Schema.For <User>().DatabaseSchemaName("other");

                _.Events.DatabaseSchemaName = "event_store";
                _.EventGraph.EventMappingFor <MembersJoined>();

                _.Connection(ConnectionSource.ConnectionString);
            }))
            {
                store.Schema.WriteDatabaseCreationScriptByType(_binAllsql);
            }

            string filename = _binAllsql.AppendPath("all.sql");

            var fileSystem = new FileSystem();

            fileSystem.FileExists(filename).ShouldBeTrue();

            var contents = fileSystem.ReadStringFromFile(filename);

            SpecificationExtensions.ShouldContain(contents, "CREATE SCHEMA event_store");
            SpecificationExtensions.ShouldContain(contents, "CREATE SCHEMA other");
            SpecificationExtensions.ShouldContain(contents, "CREATE SCHEMA yet_another");
        }
Example #2
0
        //[Fact] // -- flakey on ci
        public void writepatch_writes_patch_schema_when_autocreate_none()
        {
            StoreOptions(_ =>
            {
                _.Schema.For <User>();
                _.AutoCreateSchemaObjects = AutoCreate.None;
            });

            var directory = AppContext.BaseDirectory.AppendPath("bin", "patches");

            var fileSystem = new FileSystem();

            fileSystem.DeleteDirectory(directory);
            fileSystem.CreateDirectory(directory);

            // SAMPLE: write-patch
            // Write the patch SQL file to the @"bin\patches" directory
            theStore.Schema.WritePatch(directory.AppendPath("1.initial.sql"));
            // ENDSAMPLE

            fileSystem.FileExists(directory.AppendPath("1.initial.sql"));
            fileSystem.FileExists(directory.AppendPath("1.initial.drop.sql"));

            var patchSql = fileSystem.ReadStringFromFile(directory.AppendPath("1.initial.sql"));

            SpecificationExtensions.ShouldContain(patchSql, "CREATE TABLE public.mt_doc_user");
        }
Example #3
0
        public void do_write_the_event_sql_if_the_event_graph_is_active()
        {
            theStore.Events.AddEventType(typeof(MembersJoined));
            theStore.Events.IsActive(null).ShouldBeTrue();

            SpecificationExtensions.ShouldContain(theSchema.ToDDL(), "other.mt_streams");
        }
 public void can_create_duplicate_field_with_not_null_constraint_using_duplicate_field_attribute()
 {
     using (var store = DocumentStore.For(_ =>
     {
         _.Connection(ConnectionSource.ConnectionString);
         _.Schema.For <NonNullableDuplicateFieldTest>();
     }))
     {
         var patch = store.Schema.ToPatch();
         SpecificationExtensions.ShouldContain(patch.UpdateDDL, "non_nullable_duplicate_field    timestamp without time zone NOT NULL");
     }
 }
 public void can_create_duplicate_field_with_null_constraint()
 {
     theStore.Tenancy.Default.EnsureStorageExists(typeof(Target));
     using (var store = DocumentStore.For(_ =>
     {
         _.Connection(ConnectionSource.ConnectionString);
         _.Schema.For <Target>().Duplicate(x => x.NullableDateTime);
     }))
     {
         var patch = store.Schema.ToPatch();
         SpecificationExtensions.ShouldContain(patch.UpdateDDL, "alter table public.mt_doc_target add column nullable_date_time timestamp without time zone NULL");
     }
 }
Example #6
0
        public void generate_ddl()
        {
            theStore.Tenancy.Default.StorageFor(typeof(User));
            theStore.Tenancy.Default.StorageFor(typeof(Issue));
            theStore.Tenancy.Default.StorageFor(typeof(Company));



            var sql = theSchema.ToDDL();

            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION other.mt_upsert_user");
            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION other.mt_upsert_issue");
            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION other.mt_upsert_company");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE other.mt_doc_user");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE other.mt_doc_issue");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE other.mt_doc_company");
        }
        public void generate_ddl()
        {
            theStore.Tenancy.Default.StorageFor <User>();
            theStore.Tenancy.Default.StorageFor <Issue>();
            theStore.Tenancy.Default.StorageFor <Company>();
            theStore.Tenancy.Default.EnsureStorageExists(typeof(IntDoc));

            var sql = theStore.Schema.ToDDL();

            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION public.mt_get_next_hi");
            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION public.mt_upsert_user");
            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION public.mt_upsert_issue");
            SpecificationExtensions.ShouldContain(sql, "CREATE OR REPLACE FUNCTION public.mt_upsert_company");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE public.mt_doc_user");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE public.mt_doc_issue");
            SpecificationExtensions.ShouldContain(sql, "CREATE TABLE public.mt_doc_company");
        }
Example #8
0
        public void write_transactional_script_with_a_role()
        {
            var rules = new DdlRules();

            rules.Role = "OCD_DBA";

            var patch = new SchemaPatch(rules);

            var writer = new StringWriter();

            patch.WriteScript(writer, w =>
            {
                w.WriteLine("Hello.");
            });

            SpecificationExtensions.ShouldContain(writer.ToString(), "SET ROLE OCD_DBA;");
            SpecificationExtensions.ShouldContain(writer.ToString(), "RESET ROLE;");
        }
Example #9
0
        //[Fact] //-- flakey on ci
        public void can_do_schema_validation_negative_case_with_detected_changes()
        {
            theStore.Tenancy.Default.EnsureStorageExists(typeof(User));
            theStore.Tenancy.Default.EnsureStorageExists(typeof(Target));

            theStore.Schema.ApplyAllConfiguredChangesToDatabase();

            using (var store = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Schema.For <User>().Duplicate(x => x.UserName);
                _.Schema.For <Target>();
            }))
            {
                SpecificationExtensions.ShouldContain(Exception <SchemaValidationException> .ShouldBeThrownBy(
                                                          () => { store.Schema.AssertDatabaseMatchesConfiguration(); }).Message, "user_name");
            }
        }
Example #10
0
        public void duplicate_and_search_off_of_deep_accessor_by_date()
        {
            var targets = Target.GenerateRandomData(10).ToArray();

            StoreOptions(_ =>
            {
                _.Schema.For <Target>().Duplicate(x => x.Inner.Date);
            });

            targets.Each(x => theSession.Store(x));
            theSession.SaveChanges();

            var thirdTarget = targets.ElementAt(2);

            var queryable = theSession.Query <Target>().Where(x => x.Inner.Date == thirdTarget.Inner.Date);
            var results   = queryable.ToArray();

            results
            .Any(x => x.Id == thirdTarget.Id).ShouldBeTrue();

            SpecificationExtensions.ShouldContain(queryable.ToCommand(FetchType.FetchMany).CommandText, "inner_date = :arg0");
        }
Example #11
0
        //[Fact] //-- flakey on ci
        public void can_create_patch_for_a_single_document_type()
        {
            StoreOptions(_ =>
            {
                // This is enough to tell Marten that the User
                // document is persisted and needs schema objects
                _.Schema.For <User>();
            });

            var patch = theStore.Schema.ToPatch(typeof(User));

            SpecificationExtensions.ShouldContain(patch.UpdateDDL, "CREATE OR REPLACE FUNCTION public.mt_upsert_user");
            SpecificationExtensions.ShouldContain(patch.UpdateDDL, "CREATE TABLE public.mt_doc_user");
            SpecificationExtensions.ShouldContain(patch.RollbackDDL, "drop table if exists public.mt_doc_user cascade;");

            var file = AppContext.BaseDirectory.AppendPath("bin", "update_users.sql");

            patch.WriteUpdateFile(file);

            var text = new FileSystem().ReadStringFromFile(file);

            SpecificationExtensions.ShouldContain(text, "DO LANGUAGE plpgsql $tran$");
            SpecificationExtensions.ShouldContain(text, "$tran$;");
        }
Example #12
0
 public void then_company_table_should_be_generated_in_the_default()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE TABLE public.mt_doc_company");
 }
 public void then_the_user_table_should_be_generated_in_the_default_schema()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE TABLE yet_another.mt_doc_user");
 }
 public void do_write_the_event_sql_if_the_event_graph_is_active()
 {
     theStore.Events.IsActive(null).ShouldBeTrue();
     SpecificationExtensions.ShouldContain(_schema.ToDDL(), "other.mt_streams");
 }
Example #15
0
 public void include_the_hilo_table_by_default()
 {
     SpecificationExtensions.ShouldContain(_sql, "public.mt_hilo");
 }
Example #16
0
 public void then_the_hilo_function_should_be_generated_in_the_default_schema()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE OR REPLACE FUNCTION public.mt_get_next_hi");
 }
Example #17
0
 public void then_the_issue_function_should_be_generated_in_the_overriden_schema()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE OR REPLACE FUNCTION overriden.mt_upsert_issue");
 }
Example #18
0
 public void then_the_company_function_should_be_generated_in_the_default_schema()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE OR REPLACE FUNCTION public.mt_upsert_company");
 }
Example #19
0
 public void then_the_issue_table_should_be_generated_in_the_overriden_schema()
 {
     SpecificationExtensions.ShouldContain(_sql, "CREATE TABLE overriden.mt_doc_issue");
 }