-
Notifications
You must be signed in to change notification settings - Fork 213
/
mssql.rs
135 lines (108 loc) Β· 3.41 KB
/
mssql.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use migration_engine_tests::sync_test_api::*;
#[test_connector(tags(Mssql))]
fn reset_clears_udts(api: TestApi) {
let schema = api.schema_name();
api.raw_cmd(&format!("CREATE TYPE {}.[testType] AS TABLE (FooBar INT)", schema));
let schemas = api.query_raw(
&format!(
"SELECT * FROM sys.types WHERE SCHEMA_NAME(schema_id) = '{}' and NAME = 'testType'",
schema
),
&[],
);
assert_eq!(1, schemas.len());
api.reset().send_sync();
let schemas = api.query_raw(
&format!(
"SELECT * FROM sys.types WHERE SCHEMA_NAME(schema_id) = '{}' and NAME = 'testType'",
schema
),
&[],
);
assert_eq!(0, schemas.len());
}
#[test_connector(tags(Mssql))]
fn shared_default_constraints_are_ignored_issue_5423(api: TestApi) {
let schema = api.schema_name();
api.raw_cmd(&format!("CREATE DEFAULT [{}].catcat AS 'musti'", schema));
api.raw_cmd(&format!(
r#"
CREATE TABLE [{0}].cats (
id INT IDENTITY PRIMARY KEY,
name NVARCHAR(255) NOT NULL
)
"#,
schema
));
api.raw_cmd(&format!("sp_bindefault '{0}.catcat', '{0}.cats.name'", schema));
let dm = api.datamodel_with_provider(
r#"
model cats {
id Int @id @default(autoincrement())
name String @db.NVarChar(255)
}
"#,
);
api.schema_push(dm)
.migration_id(Some("first"))
.send()
.assert_green_bang()
.assert_no_steps();
}
#[test_connector(tags(Mssql))]
fn mssql_apply_migrations_error_output(api: TestApi) {
let dm = "";
let migrations_directory = api.create_migrations_directory();
let migration = format!(
r#"
BEGIN TRY
BEGIN TRAN;
CREATE TABLE [{schema_name}].[Cat] ( id INT IDENTITY PRIMARY KEY );
DROP TABLE [{schema_name}].[Emu];
CREATE TABLE [{schema_name}].[Emu] (
size INTEGER
);
COMMIT TRAN;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRAN;
END;
THROW
END CATCH
"#,
schema_name = api.schema_name()
);
let migration_name = api
.create_migration("01init", dm, &migrations_directory)
.draft(true)
.send_sync()
.modify_migration(|contents| {
contents.clear();
contents.push_str(&migration);
})
.into_output()
.generated_migration_name
.unwrap();
let err = api
.apply_migrations(&migrations_directory)
.send_unwrap_err()
.to_string()
.replace(&migration_name, "<migration-name>");
let expectation = expect![[r#"
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
Migration name: <migration-name>
Database error code: 3701
Database error:
Cannot drop the table 'mssql_apply_migrations_error_output.Emu', because it does not exist or you do not have permission.
"#]];
let first_segment = err
.split_terminator("DbError {")
.next()
.unwrap()
.split_terminator(" 0: ")
.next()
.unwrap();
expectation.assert_eq(first_segment)
}