Skip to content

Commit 0a96574

Browse files
committed
Bug #283: Trying to reproduct in unit test
1 parent ef86983 commit 0a96574

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

unittests/Oracle/Running_MigrationScripts/One_time_scripts.cs

+102-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
using Oracle.TestInfrastructure;
1+
using Dapper;
2+
using FluentAssertions;
3+
using grate.Configuration;
4+
using grate.Migration;
5+
using Oracle.TestInfrastructure;
26
using TestCommon.TestInfrastructure;
7+
using static grate.Configuration.KnownFolderKeys;
38

49
namespace Oracle.Running_MigrationScripts;
510

@@ -10,5 +15,101 @@ public class One_time_scripts(OracleGrateTestContext testContext, ITestOutputHel
1015
{
1116
protected override string CreateView1 => base.CreateView1 + " FROM DUAL";
1217
protected override string CreateView2 => base.CreateView2 + " FROM DUAL";
18+
19+
[Fact]
20+
public async Task Can_run_scripts_with_semicolon_in_them()
21+
{
22+
var db = TestConfig.RandomDatabase();
23+
24+
IGrateMigrator? migrator;
25+
26+
var parent = CreateRandomTempDirectory();
27+
var knownFolders = FoldersConfiguration.Default();
28+
29+
WriteSql(parent, knownFolders[Up]!.Path, "create_table.sql", @"
30+
CREATE TABLE actor (
31+
actor_id numeric NOT NULL ,
32+
first_name VARCHAR(45) NOT NULL,
33+
last_name VARCHAR(45) NOT NULL,
34+
last_update DATE NOT NULL,
35+
CONSTRAINT pk_actor PRIMARY KEY (actor_id)
36+
);");
37+
38+
var config = GrateConfigurationBuilder.Create(Context.DefaultConfiguration)
39+
.WithConnectionString(Context.ConnectionString(db))
40+
.WithSqlFilesDirectory(parent)
41+
.WithFolders(knownFolders)
42+
.Build();
43+
44+
await using (migrator = Context.Migrator.WithConfiguration(config))
45+
{
46+
await migrator.Migrate();
47+
}
48+
49+
string[] scripts;
50+
string sql = $"SELECT script_name FROM {Context.Syntax.TableWithSchema("grate", "ScriptsRun")}";
51+
52+
using (var conn = Context.GetDbConnection(Context.ConnectionString(db)))
53+
{
54+
scripts = (await conn.QueryAsync<string>(sql)).ToArray();
55+
}
56+
57+
scripts.Should().HaveCount(1);
58+
}
59+
60+
[Fact]
61+
public async Task Create_index_concurrently_works()
62+
{
63+
var db = TestConfig.RandomDatabase();
64+
65+
IGrateMigrator? migrator;
66+
67+
var parent = CreateRandomTempDirectory();
68+
var knownFolders = FoldersConfiguration.Default(null);
69+
70+
WriteSql(parent, knownFolders[Up]!.Path, "create_table_dummy.sql", @"
71+
CREATE TABLE public.table1(
72+
column1 INT PRIMARY KEY,
73+
column2 INT
74+
)
75+
");
76+
77+
WriteSql(parent, knownFolders[Indexes]!.Path, "create_index_concurrently.sql", @"
78+
DROP INDEX IF EXISTS IX_column1 CASCADE;
79+
CREATE INDEX CONCURRENTLY IX_column1 ON public.table1
80+
USING btree
81+
(
82+
column1
83+
);
84+
85+
DROP INDEX IF EXISTS IX_column2 CASCADE;
86+
CREATE INDEX CONCURRENTLY IX_column2 ON public.table1
87+
USING btree
88+
(
89+
column2
90+
);
91+
");
92+
93+
var config = GrateConfigurationBuilder.Create(Context.DefaultConfiguration)
94+
.WithConnectionString(Context.ConnectionString(db))
95+
.WithSqlFilesDirectory(parent)
96+
.WithFolders(knownFolders)
97+
.Build();
98+
99+
await using (migrator = Context.Migrator.WithConfiguration(config))
100+
{
101+
await migrator.Migrate();
102+
}
103+
104+
string[] scripts;
105+
string sql = $"SELECT script_name FROM {Context.Syntax.TableWithSchema("grate", "ScriptsRun")}";
106+
107+
using (var conn = Context.GetDbConnection(Context.ConnectionString(db)))
108+
{
109+
scripts = (await conn.QueryAsync<string>(sql)).ToArray();
110+
}
111+
112+
scripts.Should().HaveCount(2);
113+
}
13114
}
14115

0 commit comments

Comments
 (0)