Skip to content

Commit bec120e

Browse files
committed
feat(intel): add structures, notes and connection pings (notifications) to the map
1 parent f4bd875 commit bec120e

83 files changed

Lines changed: 4791 additions & 472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.8.6
1+
version = 3.9.6
22
runner.dialect = scala3
33
align.preset = more
44
maxColumn = 120

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ lazy val server = project
9898
commonSettings,
9999
Seq(
100100
libraryDependencies ++= jsoniter ++ jwt ++ tapir ++ `tapir-jsoniter` ++ `tapir-server`,
101-
libraryDependencies ++= zio ++ `zio-config` ++ `zio-test`,
101+
libraryDependencies ++= zio ++ `zio-config` ++ `zio-query` ++ `zio-test`,
102102

103103
// runtime
104104
Universal / javaOptions ++= Seq(
@@ -180,7 +180,7 @@ lazy val ui = project
180180
"dev.zio" %%% "zio-test" % Versions.zio % Test,
181181
"dev.zio" %%% "zio-test-sbt" % Versions.zio % Test,
182182
"dev.zio" %%% "zio-test-magnolia" % Versions.zio % Test
183-
)
183+
),
184184
)
185185
.dependsOn(protocol.js, `test-deps`.js % Test)
186186

constant/src/main/scala/org/updraft0/controltower/constant/types.scala

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ import scala.language.implicitConversions
44

55
// TODO: move to typeclass encoding
66

7-
// TODO: TypeId
7+
opaque type TypeId = Int
8+
9+
object TypeId:
10+
val Invalid = TypeId(-1)
11+
12+
def apply(i: Int): TypeId = i
13+
14+
given Conversion[TypeId, Int] with
15+
override def apply(s: TypeId): Int = s
16+
17+
given Ordering[TypeId] with
18+
override def compare(x: TypeId, y: TypeId): Int = x.compare(y)
19+
20+
given CanEqual[TypeId, TypeId] = CanEqual.derived
21+
22+
extension (inline v: TypeId) inline def value: Int = v
823

924
// CharacterId
1025
opaque type CharacterId = Long
@@ -93,6 +108,60 @@ object ConnectionId:
93108

94109
extension (inline v: ConnectionId) inline def value: Long = v
95110

111+
// NoteId
112+
opaque type IntelNoteId = Int
113+
114+
object IntelNoteId:
115+
val Invalid: IntelNoteId = IntelNoteId(-1)
116+
117+
def apply(i: Int): IntelNoteId = i
118+
119+
given Conversion[IntelNoteId, Int] with
120+
override def apply(s: IntelNoteId): Int = s
121+
122+
given Ordering[IntelNoteId] with
123+
override def compare(x: IntelNoteId, y: IntelNoteId): Int = x.compare(y)
124+
125+
given CanEqual[IntelNoteId, IntelNoteId] = CanEqual.derived
126+
127+
extension (inline v: IntelNoteId) inline def value: Int = v
128+
129+
// IntelStructureId
130+
opaque type IntelStructureId = Int
131+
132+
object IntelStructureId:
133+
val Invalid: IntelStructureId = IntelStructureId(-1)
134+
135+
def apply(i: Int): IntelStructureId = i
136+
137+
given Conversion[IntelStructureId, Int] with
138+
override def apply(s: IntelStructureId): Int = s
139+
140+
given Ordering[IntelStructureId] with
141+
override def compare(x: IntelStructureId, y: IntelStructureId): Int = x.compare(y)
142+
143+
given CanEqual[IntelStructureId, IntelStructureId] = CanEqual.derived
144+
145+
extension (inline v: IntelStructureId) inline def value: Int = v
146+
147+
// IntelPingId
148+
opaque type IntelPingId = Int
149+
150+
object IntelPingId:
151+
val Invalid: IntelPingId = IntelPingId(-1)
152+
153+
def apply(i: Int): IntelPingId = i
154+
155+
given Conversion[IntelPingId, Int] with
156+
override def apply(s: IntelPingId): Int = s
157+
158+
given Ordering[IntelPingId] with
159+
override def compare(x: IntelPingId, y: IntelPingId): Int = x.compare(y)
160+
161+
given CanEqual[IntelPingId, IntelPingId] = CanEqual.derived
162+
163+
extension (inline v: IntelPingId) inline def value: Int = v
164+
96165
// SigId
97166

98167
opaque type SigId = String
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
-- remove tables not to be used
2+
DROP TABLE IF EXISTS map.map_system_note;
3+
DROP TABLE IF EXISTS map.map_system_structure;
4+
5+
-- intel_system_structure
6+
CREATE TABLE map.intel_system_structure
7+
(
8+
id INTEGER PRIMARY KEY,
9+
map_id INTEGER NOT NULL REFERENCES map (id),
10+
system_id INTEGER NOT NULL,
11+
name TEXT,
12+
owner_corporation_id INTEGER REFERENCES corporation (id),
13+
item_type_id INTEGER NOT NULL,
14+
nearest_planet_idx INTEGER,
15+
nearest_moon_idx INTEGER,
16+
is_online INTEGER,
17+
is_deleted INTEGER NOT NULL DEFAULT 0,
18+
19+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
20+
updated_at INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT (unixepoch() * 1000),
21+
deleted_at INTEGER,
22+
23+
created_by_character_id INTEGER NOT NULL,
24+
updated_by_character_id INTEGER NOT NULL,
25+
deleted_by_character_id INTEGER,
26+
27+
CHECK (name is null or length(name) > 0),
28+
CHECK (is_online is null or is_online is 0 or is_online is 1),
29+
CHECK (is_deleted is 0 or (is_deleted is 1 and deleted_at is not null and deleted_by_character_id is not null))
30+
) STRICT;
31+
32+
-- intel_system
33+
CREATE TABLE map.intel_system
34+
(
35+
map_id INTEGER NOT NULL REFERENCES map (id),
36+
system_id INTEGER NOT NULL,
37+
38+
primary_corporation_id INTEGER REFERENCES corporation (id),
39+
primary_alliance_id INTEGER REFERENCES alliance (id),
40+
41+
intel_group INTEGER NOT NULL DEFAULT 0,
42+
is_empty INTEGER NOT NULL DEFAULT 0,
43+
44+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
45+
updated_at INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT (unixepoch() * 1000),
46+
created_by_character_id INTEGER NOT NULL,
47+
updated_by_character_id INTEGER NOT NULL,
48+
49+
UNIQUE (map_id, system_id),
50+
51+
CHECK (intel_group < 0 and intel_group < 4),
52+
CHECK (is_empty is 0 or is_empty is 1)
53+
) STRICT;
54+
55+
-- intel_system_note
56+
CREATE TABLE map.intel_system_note
57+
(
58+
id INTEGER PRIMARY KEY,
59+
map_id INTEGER NOT NULL REFERENCES map (id),
60+
system_id INTEGER NOT NULL,
61+
note TEXT NOT NULL,
62+
63+
is_pinned INTEGER NOT NULL DEFAULT 0,
64+
is_deleted INTEGER NOT NULL DEFAULT 0,
65+
original_id INTEGER REFERENCES intel_system_note (id),
66+
67+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
68+
created_by_character_id INTEGER NOT NULL,
69+
70+
deleted_at INTEGER,
71+
deleted_by_character_id INTEGER,
72+
73+
CHECK (length(note) > 0),
74+
CHECK (is_deleted is 0 or (is_deleted is 1 and deleted_at is not null and deleted_by_character_id is not null))
75+
) STRICT;
76+
77+
-- intel_system_ping
78+
CREATE TABLE map.intel_system_ping
79+
(
80+
id INTEGER PRIMARY KEY,
81+
map_id INTEGER NOT NULL REFERENCES map (id),
82+
system_id INTEGER NOT NULL,
83+
84+
ping_user_id INTEGER,
85+
ping_map_global INTEGER,
86+
ping_note TEXT,
87+
is_deleted INTEGER NOT NULL DEFAULT 0,
88+
89+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
90+
created_by_character_id INTEGER NOT NULL,
91+
92+
deleted_at INTEGER,
93+
deleted_by_character_id INTEGER,
94+
95+
CHECK (is_deleted is 0 or (is_deleted is 1 and deleted_at is not null and deleted_by_character_id is not null)),
96+
CHECK (ping_user_id is not null or ping_map_global is not null),
97+
CHECK (ping_map_global is null or ping_map_global is 1)
98+
) STRICT;
99+
100+
-- intel_group_stance
101+
CREATE TABLE map.intel_group_stance
102+
(
103+
map_id INTEGER NOT NULL REFERENCES map (id),
104+
105+
corporation_id INTEGER REFERENCES corporation (id),
106+
alliance_id INTEGER REFERENCES alliance (id),
107+
stance INTEGER NOT NULL,
108+
109+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
110+
created_by_character_id INTEGER NOT NULL,
111+
112+
updated_at INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT (unixepoch() * 1000),
113+
updated_by_character_id INTEGER NOT NULL,
114+
115+
UNIQUE (map_id, corporation_id, alliance_id),
116+
CHECK (corporation_id is not null or alliance_id is not null),
117+
CHECK (stance >= 0 or stance < 3)
118+
) STRICT;
119+
120+
-- intel_character
121+
CREATE TABLE map.intel_character
122+
(
123+
id INTEGER PRIMARY KEY,
124+
bloodline_id INTEGER NOT NULL,
125+
corporation_id INTEGER NOT NULL,
126+
faction_id INTEGER,
127+
gender TEXT NOT NULL,
128+
name TEXT NOT NULL,
129+
race_id INTEGER NOT NULL,
130+
security_status REAL,
131+
title TEXT,
132+
133+
created_at INTEGER NOT NULL,
134+
updated_at INTEGER NOT NULL,
135+
136+
UNIQUE (name)
137+
) STRICT;

db/src/main/scala/org/updraft0/controltower/db/context.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,43 @@ trait StringJsonExtensions extends Encoders with Decoders:
210210
sql"json_object($k1, $v1, $k2, $v2, $k3, $v3, $k4, $v4, $k5, $v5, $k6, $v6, $k7, $v7, $k8, $v8, $k9, $v9, $k10, $v10, $k11, $v11)".pure
211211
.as[JsonValue[R]]
212212

213+
inline def jsonObject16[R](
214+
inline k1: Any,
215+
inline v1: Any,
216+
inline k2: Any,
217+
inline v2: Any,
218+
inline k3: Any,
219+
inline v3: Any,
220+
inline k4: Any,
221+
inline v4: Any,
222+
inline k5: Any,
223+
inline v5: Any,
224+
inline k6: Any,
225+
inline v6: Any,
226+
inline k7: Any,
227+
inline v7: Any,
228+
inline k8: Any,
229+
inline v8: Any,
230+
inline k9: Any,
231+
inline v9: Any,
232+
inline k10: Any,
233+
inline v10: Any,
234+
inline k11: Any,
235+
inline v11: Any,
236+
inline k12: Any,
237+
inline v12: Any,
238+
inline k13: Any,
239+
inline v13: Any,
240+
inline k14: Any,
241+
inline v14: Any,
242+
inline k15: Any,
243+
inline v15: Any,
244+
inline k16: Any,
245+
inline v16: Any
246+
) =
247+
sql"json_object($k1, $v1, $k2, $v2, $k3, $v3, $k4, $v4, $k5, $v5, $k6, $v6, $k7, $v7, $k8, $v8, $k9, $v9, $k10, $v10, $k11, $v11, $k12, $v12, $k13, $v13, $k14, $v14, $k15, $v15, $k16, $v16)".pure
248+
.as[JsonValue[R]]
249+
213250
inline def jsonObject17[R](
214251
inline k1: Any,
215252
inline v1: Any,

db/src/main/scala/org/updraft0/controltower/db/datasource.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private[db] class MultiDbDatasource(cfg: Config, orig: DataSource, inSdeLoad: Bo
2828
private val logger = LoggerFactory.getLogger(getClass)
2929

3030
private inline def executeLogged(s: java.sql.Statement, q: String) =
31-
logger.trace(s"exec: ${q}")
31+
if (logger.isTraceEnabled) logger.trace(s"exec: ${q}")
3232
s.execute(q)
3333

3434
override def getConnection: Connection =

0 commit comments

Comments
 (0)