Skip to content

Commit 17a3ac8

Browse files
committed
feat(platform-deps): add saving for dependency/incompat platforms
1 parent acda7ac commit 17a3ac8

File tree

7 files changed

+466
-26
lines changed

7 files changed

+466
-26
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Add down migration script here
2+
3+
-- dependencies
4+
ALTER TABLE dependencies
5+
DROP COLUMN windows;
6+
7+
ALTER TABLE dependencies
8+
DROP COLUMN mac_arm;
9+
10+
ALTER TABLE dependencies
11+
DROP COLUMN mac_intel;
12+
13+
ALTER TABLE dependencies
14+
DROP COLUMN android32;
15+
16+
ALTER TABLE dependencies
17+
DROP COLUMN android64;
18+
19+
ALTER TABLE dependencies
20+
DROP COLUMN ios;
21+
22+
-- incompatibilities
23+
ALTER TABLE incompatibilities
24+
DROP COLUMN windows;
25+
26+
ALTER TABLE incompatibilities
27+
DROP COLUMN mac_arm;
28+
29+
ALTER TABLE incompatibilities
30+
DROP COLUMN mac_intel;
31+
32+
ALTER TABLE incompatibilities
33+
DROP COLUMN android32;
34+
35+
ALTER TABLE incompatibilities
36+
DROP COLUMN android64;
37+
38+
ALTER TABLE incompatibilities
39+
DROP COLUMN ios;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Add up migration script here
2+
3+
-- dependencies
4+
ALTER TABLE dependencies
5+
ADD COLUMN windows BOOLEAN NOT NULL DEFAULT TRUE;
6+
7+
ALTER TABLE dependencies
8+
ADD COLUMN mac_arm BOOLEAN NOT NULL DEFAULT TRUE;
9+
10+
ALTER TABLE dependencies
11+
ADD COLUMN mac_intel BOOLEAN NOT NULL DEFAULT TRUE;
12+
13+
ALTER TABLE dependencies
14+
ADD COLUMN android32 BOOLEAN NOT NULL DEFAULT TRUE;
15+
16+
ALTER TABLE dependencies
17+
ADD COLUMN android64 BOOLEAN NOT NULL DEFAULT TRUE;
18+
19+
ALTER TABLE dependencies
20+
ADD COLUMN ios BOOLEAN NOT NULL DEFAULT TRUE;
21+
22+
-- incompatibilities
23+
ALTER TABLE incompatibilities
24+
ADD COLUMN windows BOOLEAN NOT NULL DEFAULT TRUE;
25+
26+
ALTER TABLE incompatibilities
27+
ADD COLUMN mac_arm BOOLEAN NOT NULL DEFAULT TRUE;
28+
29+
ALTER TABLE incompatibilities
30+
ADD COLUMN mac_intel BOOLEAN NOT NULL DEFAULT TRUE;
31+
32+
ALTER TABLE incompatibilities
33+
ADD COLUMN android32 BOOLEAN NOT NULL DEFAULT TRUE;
34+
35+
ALTER TABLE incompatibilities
36+
ADD COLUMN android64 BOOLEAN NOT NULL DEFAULT TRUE;
37+
38+
ALTER TABLE incompatibilities
39+
ADD COLUMN ios BOOLEAN NOT NULL DEFAULT TRUE;
40+

src/database/repository/dependencies.rs

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::{
44
database::DatabaseError,
55
types::{
66
mod_json::ModJson,
7-
models::dependency::{DependencyImportance, FetchedDependency, ModVersionCompare},
7+
models::{
8+
dependency::{DependencyImportance, FetchedDependency, ModVersionCompare},
9+
mod_gd_version::VerPlatform,
10+
},
811
},
912
};
1013

@@ -26,36 +29,93 @@ pub async fn create(
2629
let mut version: Vec<String> = Vec::with_capacity(len);
2730
let mut compare: Vec<ModVersionCompare> = Vec::with_capacity(len);
2831
let mut importance: Vec<DependencyImportance> = Vec::with_capacity(len);
32+
let mut windows: Vec<bool> = Vec::with_capacity(len);
33+
let mut mac_intel: Vec<bool> = Vec::with_capacity(len);
34+
let mut mac_arm: Vec<bool> = Vec::with_capacity(len);
35+
let mut android32: Vec<bool> = Vec::with_capacity(len);
36+
let mut android64: Vec<bool> = Vec::with_capacity(len);
37+
let mut ios: Vec<bool> = Vec::with_capacity(len);
2938

3039
for i in dependencies {
3140
dependency_id.push(i.dependency_id);
3241
version.push(i.version);
3342
compare.push(i.compare);
3443
importance.push(i.importance);
44+
45+
windows.push(
46+
i.platforms
47+
.as_ref()
48+
.is_none_or(|x| x.contains(&VerPlatform::Win)),
49+
);
50+
mac_intel.push(
51+
i.platforms
52+
.as_ref()
53+
.is_none_or(|x| x.contains(&VerPlatform::MacIntel)),
54+
);
55+
mac_arm.push(
56+
i.platforms
57+
.as_ref()
58+
.is_none_or(|x| x.contains(&VerPlatform::MacArm)),
59+
);
60+
android32.push(
61+
i.platforms
62+
.as_ref()
63+
.is_none_or(|x| x.contains(&VerPlatform::Android32)),
64+
);
65+
android64.push(
66+
i.platforms
67+
.as_ref()
68+
.is_none_or(|x| x.contains(&VerPlatform::Android64)),
69+
);
70+
ios.push(
71+
i.platforms
72+
.as_ref()
73+
.is_none_or(|x| x.contains(&VerPlatform::Ios)),
74+
);
3575
}
3676

3777
sqlx::query_as!(
3878
FetchedDependency,
3979
r#"INSERT INTO dependencies
40-
(dependent_id, dependency_id, version, compare, importance)
80+
(dependent_id, dependency_id, version,
81+
compare, importance, windows, mac_intel, mac_arm,
82+
android32, android64, ios)
4183
SELECT * FROM UNNEST(
4284
$1::int4[],
4385
$2::text[],
4486
$3::text[],
4587
$4::version_compare[],
46-
$5::dependency_importance[]
88+
$5::dependency_importance[],
89+
$6::bool[],
90+
$7::bool[],
91+
$8::bool[],
92+
$9::bool[],
93+
$10::bool[],
94+
$11::bool[]
4795
)
4896
RETURNING
4997
dependent_id as mod_version_id,
5098
dependency_id,
5199
version,
52100
compare as "compare: _",
53-
importance as "importance: _""#,
101+
importance as "importance: _",
102+
windows,
103+
mac_intel,
104+
mac_arm,
105+
android32,
106+
android64,
107+
ios"#,
54108
&dependent_id,
55109
&dependency_id,
56110
&version,
57111
&compare as &[ModVersionCompare],
58-
&importance as &[DependencyImportance]
112+
&importance as &[DependencyImportance],
113+
&windows,
114+
&mac_intel,
115+
&mac_arm,
116+
&android32,
117+
&android64,
118+
&ios
59119
)
60120
.fetch_all(conn)
61121
.await

src/database/repository/incompatibilities.rs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
models::{
88
dependency::ModVersionCompare,
99
incompatibility::{FetchedIncompatibility, IncompatibilityImportance},
10+
mod_gd_version::VerPlatform,
1011
},
1112
},
1213
};
@@ -31,36 +32,93 @@ pub async fn create(
3132
let mut version: Vec<String> = Vec::with_capacity(len);
3233
let mut compare: Vec<ModVersionCompare> = Vec::with_capacity(len);
3334
let mut importance: Vec<IncompatibilityImportance> = Vec::with_capacity(len);
35+
let mut windows: Vec<bool> = Vec::with_capacity(len);
36+
let mut mac_intel: Vec<bool> = Vec::with_capacity(len);
37+
let mut mac_arm: Vec<bool> = Vec::with_capacity(len);
38+
let mut android32: Vec<bool> = Vec::with_capacity(len);
39+
let mut android64: Vec<bool> = Vec::with_capacity(len);
40+
let mut ios: Vec<bool> = Vec::with_capacity(len);
3441

3542
for i in incompats {
3643
incompatibility_id.push(i.incompatibility_id);
3744
version.push(i.version);
3845
compare.push(i.compare);
3946
importance.push(i.importance);
47+
48+
windows.push(
49+
i.platforms
50+
.as_ref()
51+
.is_none_or(|x| x.contains(&VerPlatform::Win)),
52+
);
53+
mac_intel.push(
54+
i.platforms
55+
.as_ref()
56+
.is_none_or(|x| x.contains(&VerPlatform::MacIntel)),
57+
);
58+
mac_arm.push(
59+
i.platforms
60+
.as_ref()
61+
.is_none_or(|x| x.contains(&VerPlatform::MacArm)),
62+
);
63+
android32.push(
64+
i.platforms
65+
.as_ref()
66+
.is_none_or(|x| x.contains(&VerPlatform::Android32)),
67+
);
68+
android64.push(
69+
i.platforms
70+
.as_ref()
71+
.is_none_or(|x| x.contains(&VerPlatform::Android64)),
72+
);
73+
ios.push(
74+
i.platforms
75+
.as_ref()
76+
.is_none_or(|x| x.contains(&VerPlatform::Ios)),
77+
);
4078
}
4179

4280
sqlx::query_as!(
4381
FetchedIncompatibility,
4482
r#"INSERT INTO incompatibilities
45-
(mod_id, incompatibility_id, version, compare, importance)
83+
(mod_id, incompatibility_id, version,
84+
compare, importance, windows, mac_intel, mac_arm,
85+
android32, android64, ios)
4686
SELECT * FROM UNNEST(
4787
$1::int4[],
4888
$2::text[],
4989
$3::text[],
5090
$4::version_compare[],
51-
$5::incompatibility_importance[]
91+
$5::incompatibility_importance[],
92+
$6::bool[],
93+
$7::bool[],
94+
$8::bool[],
95+
$9::bool[],
96+
$10::bool[],
97+
$11::bool[]
5298
)
5399
RETURNING
54100
mod_id,
55101
incompatibility_id,
56102
version,
57103
compare as "compare: _",
58-
importance as "importance: _""#,
104+
importance as "importance: _",
105+
windows,
106+
mac_intel,
107+
mac_arm,
108+
android32,
109+
android64,
110+
ios"#,
59111
&mod_id,
60112
&incompatibility_id,
61113
&version,
62114
&compare as &[ModVersionCompare],
63-
&importance as &[IncompatibilityImportance]
115+
&importance as &[IncompatibilityImportance],
116+
&windows,
117+
&mac_intel,
118+
&mac_arm,
119+
&android32,
120+
&android64,
121+
&ios
64122
)
65123
.fetch_all(conn)
66124
.await

0 commit comments

Comments
 (0)