For now? I'm experimenting on an old concept.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Partially migrate to SQLX, other part broken

+871 -78
+3 -2
.envrc
··· 1 - if nix flake show &> /dev/null; then 2 - use flake 1 + if nix flake show &>/dev/null; then 2 + use flake 3 3 fi 4 + export DATABASE_URL="postgres://lumina:lumina_pw@localhost:5432/lumina_config"
+719 -10
Cargo.lock
··· 27 27 ] 28 28 29 29 [[package]] 30 + name = "allocator-api2" 31 + version = "0.2.21" 32 + source = "registry+https://github.com/rust-lang/crates.io-index" 33 + checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" 34 + 35 + [[package]] 36 + name = "anyhow" 37 + version = "1.0.101" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea" 40 + 41 + [[package]] 30 42 name = "arc-swap" 31 43 version = "1.7.1" 32 44 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 66 78 ] 67 79 68 80 [[package]] 81 + name = "atoi" 82 + version = "2.0.0" 83 + source = "registry+https://github.com/rust-lang/crates.io-index" 84 + checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" 85 + dependencies = [ 86 + "num-traits", 87 + ] 88 + 89 + [[package]] 69 90 name = "atomic" 70 91 version = "0.5.3" 71 92 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 117 138 checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 118 139 119 140 [[package]] 141 + name = "base64ct" 142 + version = "1.8.3" 143 + source = "registry+https://github.com/rust-lang/crates.io-index" 144 + checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" 145 + 146 + [[package]] 120 147 name = "bb8" 121 148 version = "0.8.6" 122 149 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 172 199 173 200 [[package]] 174 201 name = "bitflags" 175 - version = "2.9.0" 202 + version = "2.11.0" 176 203 source = "registry+https://github.com/rust-lang/crates.io-index" 177 - checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" 204 + checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" 205 + dependencies = [ 206 + "serde_core", 207 + ] 178 208 179 209 [[package]] 180 210 name = "block-buffer" ··· 265 295 ] 266 296 267 297 [[package]] 298 + name = "concurrent-queue" 299 + version = "2.5.0" 300 + source = "registry+https://github.com/rust-lang/crates.io-index" 301 + checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" 302 + dependencies = [ 303 + "crossbeam-utils", 304 + ] 305 + 306 + [[package]] 307 + name = "const-oid" 308 + version = "0.9.6" 309 + source = "registry+https://github.com/rust-lang/crates.io-index" 310 + checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" 311 + 312 + [[package]] 268 313 name = "cookie" 269 314 version = "0.18.1" 270 315 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 276 321 ] 277 322 278 323 [[package]] 324 + name = "core-foundation" 325 + version = "0.10.1" 326 + source = "registry+https://github.com/rust-lang/crates.io-index" 327 + checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" 328 + dependencies = [ 329 + "core-foundation-sys", 330 + "libc", 331 + ] 332 + 333 + [[package]] 334 + name = "core-foundation-sys" 335 + version = "0.8.7" 336 + source = "registry+https://github.com/rust-lang/crates.io-index" 337 + checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 338 + 339 + [[package]] 279 340 name = "cpufeatures" 280 341 version = "0.2.17" 281 342 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 285 346 ] 286 347 287 348 [[package]] 349 + name = "crc" 350 + version = "3.4.0" 351 + source = "registry+https://github.com/rust-lang/crates.io-index" 352 + checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" 353 + dependencies = [ 354 + "crc-catalog", 355 + ] 356 + 357 + [[package]] 358 + name = "crc-catalog" 359 + version = "2.4.0" 360 + source = "registry+https://github.com/rust-lang/crates.io-index" 361 + checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" 362 + 363 + [[package]] 364 + name = "crossbeam-queue" 365 + version = "0.3.12" 366 + source = "registry+https://github.com/rust-lang/crates.io-index" 367 + checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115" 368 + dependencies = [ 369 + "crossbeam-utils", 370 + ] 371 + 372 + [[package]] 373 + name = "crossbeam-utils" 374 + version = "0.8.21" 375 + source = "registry+https://github.com/rust-lang/crates.io-index" 376 + checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" 377 + 378 + [[package]] 288 379 name = "crypto-common" 289 380 version = "0.1.6" 290 381 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 310 401 checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" 311 402 312 403 [[package]] 404 + name = "der" 405 + version = "0.7.10" 406 + source = "registry+https://github.com/rust-lang/crates.io-index" 407 + checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" 408 + dependencies = [ 409 + "const-oid", 410 + "pem-rfc7468", 411 + "zeroize", 412 + ] 413 + 414 + [[package]] 313 415 name = "deranged" 314 416 version = "0.4.0" 315 417 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 358 460 checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 359 461 dependencies = [ 360 462 "block-buffer", 463 + "const-oid", 361 464 "crypto-common", 362 465 "subtle", 363 466 ] ··· 380 483 checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" 381 484 382 485 [[package]] 486 + name = "dotenvy" 487 + version = "0.15.7" 488 + source = "registry+https://github.com/rust-lang/crates.io-index" 489 + checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" 490 + 491 + [[package]] 383 492 name = "either" 384 493 version = "1.15.0" 385 494 source = "registry+https://github.com/rust-lang/crates.io-index" 386 495 checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 496 + dependencies = [ 497 + "serde", 498 + ] 387 499 388 500 [[package]] 389 501 name = "encoding_rs" ··· 408 520 dependencies = [ 409 521 "libc", 410 522 "windows-sys 0.59.0", 523 + ] 524 + 525 + [[package]] 526 + name = "etcetera" 527 + version = "0.8.0" 528 + source = "registry+https://github.com/rust-lang/crates.io-index" 529 + checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" 530 + dependencies = [ 531 + "cfg-if", 532 + "home", 533 + "windows-sys 0.48.0", 534 + ] 535 + 536 + [[package]] 537 + name = "event-listener" 538 + version = "5.4.1" 539 + source = "registry+https://github.com/rust-lang/crates.io-index" 540 + checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" 541 + dependencies = [ 542 + "concurrent-queue", 543 + "parking", 544 + "pin-project-lite", 411 545 ] 412 546 413 547 [[package]] ··· 437 571 ] 438 572 439 573 [[package]] 574 + name = "flume" 575 + version = "0.11.1" 576 + source = "registry+https://github.com/rust-lang/crates.io-index" 577 + checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" 578 + dependencies = [ 579 + "futures-core", 580 + "futures-sink", 581 + "spin", 582 + ] 583 + 584 + [[package]] 440 585 name = "fnv" 441 586 version = "1.0.7" 442 587 source = "registry+https://github.com/rust-lang/crates.io-index" 443 588 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 589 + 590 + [[package]] 591 + name = "foldhash" 592 + version = "0.1.5" 593 + source = "registry+https://github.com/rust-lang/crates.io-index" 594 + checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" 595 + 596 + [[package]] 597 + name = "foreign-types" 598 + version = "0.3.2" 599 + source = "registry+https://github.com/rust-lang/crates.io-index" 600 + checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" 601 + dependencies = [ 602 + "foreign-types-shared", 603 + ] 604 + 605 + [[package]] 606 + name = "foreign-types-shared" 607 + version = "0.1.1" 608 + source = "registry+https://github.com/rust-lang/crates.io-index" 609 + checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" 444 610 445 611 [[package]] 446 612 name = "form_urlencoded" ··· 491 657 "futures-core", 492 658 "futures-task", 493 659 "futures-util", 660 + ] 661 + 662 + [[package]] 663 + name = "futures-intrusive" 664 + version = "0.5.0" 665 + source = "registry+https://github.com/rust-lang/crates.io-index" 666 + checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" 667 + dependencies = [ 668 + "futures-core", 669 + "lock_api", 670 + "parking_lot", 494 671 ] 495 672 496 673 [[package]] ··· 622 799 version = "0.15.2" 623 800 source = "registry+https://github.com/rust-lang/crates.io-index" 624 801 checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 802 + dependencies = [ 803 + "allocator-api2", 804 + "equivalent", 805 + "foldhash", 806 + ] 807 + 808 + [[package]] 809 + name = "hashlink" 810 + version = "0.10.0" 811 + source = "registry+https://github.com/rust-lang/crates.io-index" 812 + checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" 813 + dependencies = [ 814 + "hashbrown", 815 + ] 625 816 626 817 [[package]] 627 818 name = "heck" ··· 642 833 checksum = "fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e" 643 834 644 835 [[package]] 836 + name = "hex" 837 + version = "0.4.3" 838 + source = "registry+https://github.com/rust-lang/crates.io-index" 839 + checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 840 + 841 + [[package]] 842 + name = "hkdf" 843 + version = "0.12.4" 844 + source = "registry+https://github.com/rust-lang/crates.io-index" 845 + checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" 846 + dependencies = [ 847 + "hmac", 848 + ] 849 + 850 + [[package]] 645 851 name = "hmac" 646 852 version = "0.12.1" 647 853 source = "registry+https://github.com/rust-lang/crates.io-index" 648 854 checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" 649 855 dependencies = [ 650 856 "digest", 857 + ] 858 + 859 + [[package]] 860 + name = "home" 861 + version = "0.5.12" 862 + source = "registry+https://github.com/rust-lang/crates.io-index" 863 + checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" 864 + dependencies = [ 865 + "windows-sys 0.61.2", 651 866 ] 652 867 653 868 [[package]] ··· 925 1140 version = "1.5.0" 926 1141 source = "registry+https://github.com/rust-lang/crates.io-index" 927 1142 checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 1143 + dependencies = [ 1144 + "spin", 1145 + ] 928 1146 929 1147 [[package]] 930 1148 name = "libc" ··· 933 1151 checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 934 1152 935 1153 [[package]] 1154 + name = "libm" 1155 + version = "0.2.16" 1156 + source = "registry+https://github.com/rust-lang/crates.io-index" 1157 + checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" 1158 + 1159 + [[package]] 1160 + name = "libsqlite3-sys" 1161 + version = "0.30.1" 1162 + source = "registry+https://github.com/rust-lang/crates.io-index" 1163 + checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" 1164 + dependencies = [ 1165 + "pkg-config", 1166 + "vcpkg", 1167 + ] 1168 + 1169 + [[package]] 936 1170 name = "linux-raw-sys" 937 1171 version = "0.9.4" 938 1172 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 979 1213 name = "lumina-server" 980 1214 version = "0.1.0" 981 1215 dependencies = [ 1216 + "anyhow", 982 1217 "base64", 983 1218 "bb8", 984 1219 "bb8-postgres", ··· 992 1227 "rocket_ws", 993 1228 "serde", 994 1229 "serde_json", 1230 + "sqlx", 995 1231 "tabled", 996 1232 "time", 997 1233 "tokio", 998 - "tokio-postgres", 999 1234 "uuid", 1000 1235 ] 1001 1236 ··· 1070 1305 ] 1071 1306 1072 1307 [[package]] 1308 + name = "native-tls" 1309 + version = "0.2.18" 1310 + source = "registry+https://github.com/rust-lang/crates.io-index" 1311 + checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" 1312 + dependencies = [ 1313 + "libc", 1314 + "log", 1315 + "openssl", 1316 + "openssl-probe", 1317 + "openssl-sys", 1318 + "schannel", 1319 + "security-framework", 1320 + "security-framework-sys", 1321 + "tempfile", 1322 + ] 1323 + 1324 + [[package]] 1073 1325 name = "nu-ansi-term" 1074 1326 version = "0.46.0" 1075 1327 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1087 1339 dependencies = [ 1088 1340 "num-integer", 1089 1341 "num-traits", 1342 + ] 1343 + 1344 + [[package]] 1345 + name = "num-bigint-dig" 1346 + version = "0.8.6" 1347 + source = "registry+https://github.com/rust-lang/crates.io-index" 1348 + checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" 1349 + dependencies = [ 1350 + "lazy_static", 1351 + "libm", 1352 + "num-integer", 1353 + "num-iter", 1354 + "num-traits", 1355 + "rand 0.8.5", 1356 + "smallvec", 1357 + "zeroize", 1090 1358 ] 1091 1359 1092 1360 [[package]] ··· 1105 1373 ] 1106 1374 1107 1375 [[package]] 1376 + name = "num-iter" 1377 + version = "0.1.45" 1378 + source = "registry+https://github.com/rust-lang/crates.io-index" 1379 + checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" 1380 + dependencies = [ 1381 + "autocfg", 1382 + "num-integer", 1383 + "num-traits", 1384 + ] 1385 + 1386 + [[package]] 1108 1387 name = "num-traits" 1109 1388 version = "0.2.19" 1110 1389 source = "registry+https://github.com/rust-lang/crates.io-index" 1111 1390 checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 1112 1391 dependencies = [ 1113 1392 "autocfg", 1393 + "libm", 1114 1394 ] 1115 1395 1116 1396 [[package]] ··· 1139 1419 checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 1140 1420 1141 1421 [[package]] 1422 + name = "openssl" 1423 + version = "0.10.75" 1424 + source = "registry+https://github.com/rust-lang/crates.io-index" 1425 + checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" 1426 + dependencies = [ 1427 + "bitflags", 1428 + "cfg-if", 1429 + "foreign-types", 1430 + "libc", 1431 + "once_cell", 1432 + "openssl-macros", 1433 + "openssl-sys", 1434 + ] 1435 + 1436 + [[package]] 1437 + name = "openssl-macros" 1438 + version = "0.1.1" 1439 + source = "registry+https://github.com/rust-lang/crates.io-index" 1440 + checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" 1441 + dependencies = [ 1442 + "proc-macro2", 1443 + "quote", 1444 + "syn", 1445 + ] 1446 + 1447 + [[package]] 1448 + name = "openssl-probe" 1449 + version = "0.2.1" 1450 + source = "registry+https://github.com/rust-lang/crates.io-index" 1451 + checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" 1452 + 1453 + [[package]] 1454 + name = "openssl-sys" 1455 + version = "0.9.111" 1456 + source = "registry+https://github.com/rust-lang/crates.io-index" 1457 + checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" 1458 + dependencies = [ 1459 + "cc", 1460 + "libc", 1461 + "pkg-config", 1462 + "vcpkg", 1463 + ] 1464 + 1465 + [[package]] 1142 1466 name = "overload" 1143 1467 version = "0.1.1" 1144 1468 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1154 1478 "fnv", 1155 1479 "unicode-width", 1156 1480 ] 1481 + 1482 + [[package]] 1483 + name = "parking" 1484 + version = "2.2.1" 1485 + source = "registry+https://github.com/rust-lang/crates.io-index" 1486 + checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" 1157 1487 1158 1488 [[package]] 1159 1489 name = "parking_lot" ··· 1202 1532 ] 1203 1533 1204 1534 [[package]] 1535 + name = "pem-rfc7468" 1536 + version = "0.7.0" 1537 + source = "registry+https://github.com/rust-lang/crates.io-index" 1538 + checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" 1539 + dependencies = [ 1540 + "base64ct", 1541 + ] 1542 + 1543 + [[package]] 1205 1544 name = "percent-encoding" 1206 1545 version = "2.3.1" 1207 1546 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1238 1577 checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 1239 1578 1240 1579 [[package]] 1580 + name = "pkcs1" 1581 + version = "0.7.5" 1582 + source = "registry+https://github.com/rust-lang/crates.io-index" 1583 + checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" 1584 + dependencies = [ 1585 + "der", 1586 + "pkcs8", 1587 + "spki", 1588 + ] 1589 + 1590 + [[package]] 1591 + name = "pkcs8" 1592 + version = "0.10.2" 1593 + source = "registry+https://github.com/rust-lang/crates.io-index" 1594 + checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" 1595 + dependencies = [ 1596 + "der", 1597 + "spki", 1598 + ] 1599 + 1600 + [[package]] 1601 + name = "pkg-config" 1602 + version = "0.3.32" 1603 + source = "registry+https://github.com/rust-lang/crates.io-index" 1604 + checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" 1605 + 1606 + [[package]] 1241 1607 name = "postgres-protocol" 1242 1608 version = "0.6.8" 1243 1609 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1264 1630 "bytes", 1265 1631 "fallible-iterator", 1266 1632 "postgres-protocol", 1267 - "uuid", 1268 1633 ] 1269 1634 1270 1635 [[package]] ··· 1591 1956 ] 1592 1957 1593 1958 [[package]] 1959 + name = "rsa" 1960 + version = "0.9.10" 1961 + source = "registry+https://github.com/rust-lang/crates.io-index" 1962 + checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" 1963 + dependencies = [ 1964 + "const-oid", 1965 + "digest", 1966 + "num-bigint-dig", 1967 + "num-integer", 1968 + "num-traits", 1969 + "pkcs1", 1970 + "pkcs8", 1971 + "rand_core 0.6.4", 1972 + "signature", 1973 + "spki", 1974 + "subtle", 1975 + "zeroize", 1976 + ] 1977 + 1978 + [[package]] 1594 1979 name = "rustc-demangle" 1595 1980 version = "0.1.24" 1596 1981 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1622 2007 checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" 1623 2008 1624 2009 [[package]] 2010 + name = "schannel" 2011 + version = "0.1.28" 2012 + source = "registry+https://github.com/rust-lang/crates.io-index" 2013 + checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" 2014 + dependencies = [ 2015 + "windows-sys 0.61.2", 2016 + ] 2017 + 2018 + [[package]] 1625 2019 name = "scoped-tls" 1626 2020 version = "1.0.1" 1627 2021 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1634 2028 checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 1635 2029 1636 2030 [[package]] 2031 + name = "security-framework" 2032 + version = "3.7.0" 2033 + source = "registry+https://github.com/rust-lang/crates.io-index" 2034 + checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" 2035 + dependencies = [ 2036 + "bitflags", 2037 + "core-foundation", 2038 + "core-foundation-sys", 2039 + "libc", 2040 + "security-framework-sys", 2041 + ] 2042 + 2043 + [[package]] 2044 + name = "security-framework-sys" 2045 + version = "2.17.0" 2046 + source = "registry+https://github.com/rust-lang/crates.io-index" 2047 + checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" 2048 + dependencies = [ 2049 + "core-foundation-sys", 2050 + "libc", 2051 + ] 2052 + 2053 + [[package]] 1637 2054 name = "serde" 1638 - version = "1.0.219" 2055 + version = "1.0.228" 2056 + source = "registry+https://github.com/rust-lang/crates.io-index" 2057 + checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" 2058 + dependencies = [ 2059 + "serde_core", 2060 + "serde_derive", 2061 + ] 2062 + 2063 + [[package]] 2064 + name = "serde_core" 2065 + version = "1.0.228" 1639 2066 source = "registry+https://github.com/rust-lang/crates.io-index" 1640 - checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 2067 + checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" 1641 2068 dependencies = [ 1642 2069 "serde_derive", 1643 2070 ] 1644 2071 1645 2072 [[package]] 1646 2073 name = "serde_derive" 1647 - version = "1.0.219" 2074 + version = "1.0.228" 1648 2075 source = "registry+https://github.com/rust-lang/crates.io-index" 1649 - checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 2076 + checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" 1650 2077 dependencies = [ 1651 2078 "proc-macro2", 1652 2079 "quote", ··· 1671 2098 source = "registry+https://github.com/rust-lang/crates.io-index" 1672 2099 checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" 1673 2100 dependencies = [ 2101 + "serde", 2102 + ] 2103 + 2104 + [[package]] 2105 + name = "serde_urlencoded" 2106 + version = "0.7.1" 2107 + source = "registry+https://github.com/rust-lang/crates.io-index" 2108 + checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" 2109 + dependencies = [ 2110 + "form_urlencoded", 2111 + "itoa", 2112 + "ryu", 1674 2113 "serde", 1675 2114 ] 1676 2115 ··· 1727 2166 ] 1728 2167 1729 2168 [[package]] 2169 + name = "signature" 2170 + version = "2.2.0" 2171 + source = "registry+https://github.com/rust-lang/crates.io-index" 2172 + checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" 2173 + dependencies = [ 2174 + "digest", 2175 + "rand_core 0.6.4", 2176 + ] 2177 + 2178 + [[package]] 1730 2179 name = "siphasher" 1731 2180 version = "1.0.1" 1732 2181 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1746 2195 version = "1.15.0" 1747 2196 source = "registry+https://github.com/rust-lang/crates.io-index" 1748 2197 checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" 2198 + dependencies = [ 2199 + "serde", 2200 + ] 1749 2201 1750 2202 [[package]] 1751 2203 name = "socket2" ··· 1762 2214 version = "0.9.8" 1763 2215 source = "registry+https://github.com/rust-lang/crates.io-index" 1764 2216 checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" 2217 + dependencies = [ 2218 + "lock_api", 2219 + ] 2220 + 2221 + [[package]] 2222 + name = "spki" 2223 + version = "0.7.3" 2224 + source = "registry+https://github.com/rust-lang/crates.io-index" 2225 + checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" 2226 + dependencies = [ 2227 + "base64ct", 2228 + "der", 2229 + ] 2230 + 2231 + [[package]] 2232 + name = "sqlx" 2233 + version = "0.8.6" 2234 + source = "registry+https://github.com/rust-lang/crates.io-index" 2235 + checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc" 2236 + dependencies = [ 2237 + "sqlx-core", 2238 + "sqlx-macros", 2239 + "sqlx-mysql", 2240 + "sqlx-postgres", 2241 + "sqlx-sqlite", 2242 + ] 2243 + 2244 + [[package]] 2245 + name = "sqlx-core" 2246 + version = "0.8.6" 2247 + source = "registry+https://github.com/rust-lang/crates.io-index" 2248 + checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6" 2249 + dependencies = [ 2250 + "base64", 2251 + "bytes", 2252 + "crc", 2253 + "crossbeam-queue", 2254 + "either", 2255 + "event-listener", 2256 + "futures-core", 2257 + "futures-intrusive", 2258 + "futures-io", 2259 + "futures-util", 2260 + "hashbrown", 2261 + "hashlink", 2262 + "indexmap", 2263 + "log", 2264 + "memchr", 2265 + "native-tls", 2266 + "once_cell", 2267 + "percent-encoding", 2268 + "serde", 2269 + "serde_json", 2270 + "sha2", 2271 + "smallvec", 2272 + "thiserror 2.0.18", 2273 + "tokio", 2274 + "tokio-stream", 2275 + "tracing", 2276 + "url", 2277 + "uuid", 2278 + ] 2279 + 2280 + [[package]] 2281 + name = "sqlx-macros" 2282 + version = "0.8.6" 2283 + source = "registry+https://github.com/rust-lang/crates.io-index" 2284 + checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d" 2285 + dependencies = [ 2286 + "proc-macro2", 2287 + "quote", 2288 + "sqlx-core", 2289 + "sqlx-macros-core", 2290 + "syn", 2291 + ] 2292 + 2293 + [[package]] 2294 + name = "sqlx-macros-core" 2295 + version = "0.8.6" 2296 + source = "registry+https://github.com/rust-lang/crates.io-index" 2297 + checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b" 2298 + dependencies = [ 2299 + "dotenvy", 2300 + "either", 2301 + "heck", 2302 + "hex", 2303 + "once_cell", 2304 + "proc-macro2", 2305 + "quote", 2306 + "serde", 2307 + "serde_json", 2308 + "sha2", 2309 + "sqlx-core", 2310 + "sqlx-mysql", 2311 + "sqlx-postgres", 2312 + "sqlx-sqlite", 2313 + "syn", 2314 + "tokio", 2315 + "url", 2316 + ] 2317 + 2318 + [[package]] 2319 + name = "sqlx-mysql" 2320 + version = "0.8.6" 2321 + source = "registry+https://github.com/rust-lang/crates.io-index" 2322 + checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" 2323 + dependencies = [ 2324 + "atoi", 2325 + "base64", 2326 + "bitflags", 2327 + "byteorder", 2328 + "bytes", 2329 + "crc", 2330 + "digest", 2331 + "dotenvy", 2332 + "either", 2333 + "futures-channel", 2334 + "futures-core", 2335 + "futures-io", 2336 + "futures-util", 2337 + "generic-array", 2338 + "hex", 2339 + "hkdf", 2340 + "hmac", 2341 + "itoa", 2342 + "log", 2343 + "md-5", 2344 + "memchr", 2345 + "once_cell", 2346 + "percent-encoding", 2347 + "rand 0.8.5", 2348 + "rsa", 2349 + "serde", 2350 + "sha1", 2351 + "sha2", 2352 + "smallvec", 2353 + "sqlx-core", 2354 + "stringprep", 2355 + "thiserror 2.0.18", 2356 + "tracing", 2357 + "uuid", 2358 + "whoami", 2359 + ] 2360 + 2361 + [[package]] 2362 + name = "sqlx-postgres" 2363 + version = "0.8.6" 2364 + source = "registry+https://github.com/rust-lang/crates.io-index" 2365 + checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" 2366 + dependencies = [ 2367 + "atoi", 2368 + "base64", 2369 + "bitflags", 2370 + "byteorder", 2371 + "crc", 2372 + "dotenvy", 2373 + "etcetera", 2374 + "futures-channel", 2375 + "futures-core", 2376 + "futures-util", 2377 + "hex", 2378 + "hkdf", 2379 + "hmac", 2380 + "home", 2381 + "itoa", 2382 + "log", 2383 + "md-5", 2384 + "memchr", 2385 + "once_cell", 2386 + "rand 0.8.5", 2387 + "serde", 2388 + "serde_json", 2389 + "sha2", 2390 + "smallvec", 2391 + "sqlx-core", 2392 + "stringprep", 2393 + "thiserror 2.0.18", 2394 + "tracing", 2395 + "uuid", 2396 + "whoami", 2397 + ] 2398 + 2399 + [[package]] 2400 + name = "sqlx-sqlite" 2401 + version = "0.8.6" 2402 + source = "registry+https://github.com/rust-lang/crates.io-index" 2403 + checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea" 2404 + dependencies = [ 2405 + "atoi", 2406 + "flume", 2407 + "futures-channel", 2408 + "futures-core", 2409 + "futures-executor", 2410 + "futures-intrusive", 2411 + "futures-util", 2412 + "libsqlite3-sys", 2413 + "log", 2414 + "percent-encoding", 2415 + "serde", 2416 + "serde_urlencoded", 2417 + "sqlx-core", 2418 + "thiserror 2.0.18", 2419 + "tracing", 2420 + "url", 2421 + "uuid", 2422 + ] 1765 2423 1766 2424 [[package]] 1767 2425 name = "stable-pattern" ··· 1888 2546 source = "registry+https://github.com/rust-lang/crates.io-index" 1889 2547 checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 1890 2548 dependencies = [ 1891 - "thiserror-impl", 2549 + "thiserror-impl 1.0.69", 2550 + ] 2551 + 2552 + [[package]] 2553 + name = "thiserror" 2554 + version = "2.0.18" 2555 + source = "registry+https://github.com/rust-lang/crates.io-index" 2556 + checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" 2557 + dependencies = [ 2558 + "thiserror-impl 2.0.18", 1892 2559 ] 1893 2560 1894 2561 [[package]] ··· 1896 2563 version = "1.0.69" 1897 2564 source = "registry+https://github.com/rust-lang/crates.io-index" 1898 2565 checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 2566 + dependencies = [ 2567 + "proc-macro2", 2568 + "quote", 2569 + "syn", 2570 + ] 2571 + 2572 + [[package]] 2573 + name = "thiserror-impl" 2574 + version = "2.0.18" 2575 + source = "registry+https://github.com/rust-lang/crates.io-index" 2576 + checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" 1899 2577 dependencies = [ 1900 2578 "proc-macro2", 1901 2579 "quote", ··· 2105 2783 source = "registry+https://github.com/rust-lang/crates.io-index" 2106 2784 checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" 2107 2785 dependencies = [ 2786 + "log", 2108 2787 "pin-project-lite", 2109 2788 "tracing-attributes", 2110 2789 "tracing-core", ··· 2180 2859 "log", 2181 2860 "rand 0.8.5", 2182 2861 "sha1", 2183 - "thiserror", 2862 + "thiserror 1.0.69", 2184 2863 "url", 2185 2864 "utf-8", 2186 2865 ] ··· 2295 2974 checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" 2296 2975 2297 2976 [[package]] 2977 + name = "vcpkg" 2978 + version = "0.2.15" 2979 + source = "registry+https://github.com/rust-lang/crates.io-index" 2980 + checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 2981 + 2982 + [[package]] 2298 2983 name = "version_check" 2299 2984 version = "0.9.5" 2300 2985 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2440 3125 ] 2441 3126 2442 3127 [[package]] 3128 + name = "windows-link" 3129 + version = "0.2.1" 3130 + source = "registry+https://github.com/rust-lang/crates.io-index" 3131 + checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 3132 + 3133 + [[package]] 3134 + name = "windows-sys" 3135 + version = "0.48.0" 3136 + source = "registry+https://github.com/rust-lang/crates.io-index" 3137 + checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 3138 + dependencies = [ 3139 + "windows-targets 0.48.5", 3140 + ] 3141 + 3142 + [[package]] 2443 3143 name = "windows-sys" 2444 3144 version = "0.52.0" 2445 3145 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2455 3155 checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 2456 3156 dependencies = [ 2457 3157 "windows-targets 0.52.6", 3158 + ] 3159 + 3160 + [[package]] 3161 + name = "windows-sys" 3162 + version = "0.61.2" 3163 + source = "registry+https://github.com/rust-lang/crates.io-index" 3164 + checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 3165 + dependencies = [ 3166 + "windows-link", 2458 3167 ] 2459 3168 2460 3169 [[package]]
+17 -2
Justfile
··· 55 55 [doc("Just runs the Podman image for a Redis and Postgres server for local development run to connect to.")] 56 56 [group("local-devel")] 57 57 local-devel-prep: create-data-dirs 58 - podman run --replace --name lumina-redis -p 6379:6379 -v ./data/redis:/data -d docker.io/redis/redis-stack:7.2.0-v18 59 - podman run --replace -d -p 5432:5432 --name luminadb -e POSTGRES_USER=lumina -e POSTGRES_PASSWORD=lumina_pw -e POSTGRES_DB=lumina_config -v ./data/postgres:/var/lib/postgresql/data:Z docker.io/library/postgres:17-alpine3.22 58 + # The redis container can be replaced if it already exists, but the postgres container needs to be checked, due to 59 + # sqlx needing to connect to it to create the database and run the migrations, so if it is restarted, it may not be 60 + # ready by the time sqlx tries to connect. 61 + podman run --replace --name lumina-redis -p 6379:6379 -v ./data/redis:/data -d docker.io/redis/redis-stack:7.2.0-v18 62 + @podman inspect -f '{{{{.State.Running}}}}' luminadb 2>/dev/null | grep -q 'true' \ 63 + && echo "luminadb is already running." \ 64 + || podman run -d -p 5432:5432 \ 65 + --name luminadb \ 66 + -e POSTGRES_USER=lumina \ 67 + -e POSTGRES_PASSWORD=lumina_pw \ 68 + -e POSTGRES_DB=lumina_config \ 69 + -v ./data/postgres:/var/lib/postgresql/data:Z \ 70 + docker.io/library/postgres:17-alpine3.22 71 + sqlx db create 72 + sqlx migrate run 73 + echo "Postgres database created and migrations ran" 74 + 60 75 61 76 [doc("Run the server in development mode")] 62 77 [group("local-devel")]
-4
SQL/create_pg.sql migrations/0001_luminadb.sql
··· 16 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 17 */ 18 18 19 - /* 20 - This file is also auto-included by server/src/database.rs, which uses it to create the database on first launch. 21 - */ 22 - 23 19 -- Create logs table 24 20 CREATE TABLE IF NOT EXISTS logs 25 21 (
+36 -21
flake.nix
··· 1 1 { 2 2 description = "Lumina Development Environment"; 3 - 4 3 inputs = { 5 4 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 6 5 utils.url = "github:numtide/flake-utils"; ··· 21 20 system: 22 21 let 23 22 pkgs = import nixpkgs { inherit system; }; 24 - # Define the Rust toolchain using Fenix 25 23 rustToolchain = fenix.packages.${system}.stable.withComponents [ 26 24 "cargo" 27 25 "rustc" ··· 30 28 "rust-analyzer" 31 29 "rust-src" 32 30 ]; 31 + # Define libraries in one place to avoid repetition 32 + libraries = with pkgs; [ 33 + stdenv.cc.cc 34 + glib 35 + dbus 36 + curl 37 + openssl 38 + ]; 39 + 40 + packages = with pkgs; [ 41 + 42 + # Language tool chains: Rust, Gleam 43 + rustToolchain 44 + gleam 45 + bun 46 + # For tidying and typing 47 + # nodePackages.prettier 48 + sqlx-cli 49 + 50 + # Helpers on OS level 51 + pkg-config 52 + 53 + # Podman 54 + podman 55 + 56 + # Runners 57 + watchexec 58 + just 59 + ]; 33 60 in 34 61 { 35 62 devShells.default = pkgs.mkShell { 36 - buildInputs = with pkgs; [ 37 - # Language tool chains: Rust, Gleam 38 - rustToolchain 39 - gleam 40 - bun 41 - # For tidying and typing 42 - # nodePackages.prettier 43 - 44 - # Helpers on OS level 45 - pkg-config 46 - dbus 47 - 48 - # Podman 49 - podman 63 + # Tools go here 64 + nativeBuildInputs = [ pkgs.pkg-config ]; 50 65 51 - # Runners 52 - watchexec 53 - just 54 - ]; 66 + # Libraries go here 67 + buildInputs = packages ++ libraries; 55 68 56 69 shellHook = '' 57 - export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH" 70 + export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH" 71 + 58 72 bun i --cwd=client/ 59 73 echo "❄️ dev environment loaded" 60 74 just --list ··· 65 79 }; 66 80 } 67 81 ); 82 + 68 83 }
+7 -1
server/Cargo.toml
··· 16 16 ws = { package = "rocket_ws", version = "0.1.1" } 17 17 serde_json = "1.0.140" 18 18 uuid = { version = "1.16.0", features = ["v4", "serde"] } 19 + sqlx = { version = "0.8.6", features = [ 20 + "postgres", 21 + "runtime-tokio", 22 + "tls-native-tls", 23 + "uuid", 24 + ] } 25 + anyhow = "1.0.101" 19 26 cynthia_con = { version = "0.1.4" } 20 27 dotenv = "0.15.0" 21 - tokio-postgres = { version = "0.7.13", features = ["with-uuid-1"] } 22 28 bcrypt = "0.17.0" 23 29 bb8 = "0.8" 24 30 bb8-postgres = "0.8"
+88 -37
server/src/database.rs
··· 22 22 use crate::EnvVar::*; 23 23 use crate::errors::LuminaError::{self}; 24 24 use crate::helpers::events::EventLogger; 25 - use crate::postgres; 26 25 use crate::timeline; 27 26 use crate::{info_elog, success_elog, warn_elog}; 28 27 use bb8::Pool; 29 - use bb8_postgres::PostgresConnectionManager; 30 28 use bb8_redis::RedisConnectionManager; 31 29 use cynthia_con::{CynthiaColors, CynthiaStyles}; 30 + use sqlx::postgres::PgPool; 32 31 use std::time::Duration; 33 - use tokio_postgres::NoTls; 32 + 33 + struct DatabaseConfig { 34 + postgres_username: String, 35 + postgres_password: Option<String>, 36 + postgres_host: String, 37 + postgres_port: u16, 38 + postgres_dbname: String, 39 + redis_url: String, 40 + } 34 41 35 42 pub(crate) async fn setup() -> Result<PgConn, LuminaError> { 36 43 let ev_log = EventLogger::new(&None); ··· 56 63 }; 57 64 58 65 { 59 - let pg_config: tokio_postgres::Config = { 66 + let pg_config: DatabaseConfig = { 60 67 let mut uuu = ( 61 68 "unspecified database".to_string(), 62 69 "unspecified host".to_string(), 63 70 "unknown port".to_string(), 64 71 ); 65 - let mut pg_config = postgres::Config::new(); 66 - pg_config.user(&{ 67 - std::env::var("LUMINA_POSTGRES_USERNAME").unwrap_or("lumina".to_string()) 68 - }); 72 + let mut pg_config = DatabaseConfig { 73 + postgres_username: std::env::var("LUMINA_POSTGRES_USERNAME") 74 + .unwrap_or("lumina".to_string()), 75 + postgres_password: std::env::var("LUMINA_POSTGRES_PASSWORD").ok(), 76 + postgres_host: std::env::var("LUMINA_POSTGRES_HOST") 77 + .unwrap_or("localhost".to_string()), 78 + postgres_port: std::env::var("LUMINA_POSTGRES_PORT") 79 + .ok() 80 + .and_then(|p| p.parse::<u16>().ok()) 81 + .unwrap_or(5432), 82 + postgres_dbname: std::env::var("LUMINA_POSTGRES_DATABASE") 83 + .unwrap_or("lumina_config".to_string()), 84 + redis_url, 85 + }; 86 + pg_config.postgres_username = 87 + std::env::var("LUMINA_POSTGRES_USERNAME").unwrap_or("lumina".to_string()); 69 88 let dbname = 70 89 std::env::var("LUMINA_POSTGRES_DATABASE").unwrap_or("lumina_config".to_string()); 71 90 uuu.0 = dbname.clone(); 72 - pg_config.dbname(&dbname); 91 + pg_config.postgres_dbname = dbname; 73 92 let port = match std::env::var("LUMINA_POSTGRES_PORT") { 74 93 Err(..) => { 75 94 warn_elog!( ··· 82 101 }; 83 102 uuu.2 = port.clone(); 84 103 // Parse the port as u16, if it fails, return an error 85 - pg_config.port( 86 - port.parse::<u16>() 87 - .map_err(|_| LuminaError::ConfInvalid(LUMINA_POSTGRES_PORT))?, 88 - ); 104 + pg_config.postgres_port = port 105 + .parse::<u16>() 106 + .map_err(|_| LuminaError::ConfInvalid(LUMINA_POSTGRES_PORT))?; 89 107 match std::env::var("LUMINA_POSTGRES_HOST") { 90 108 Ok(val) => { 91 109 uuu.1 = val.clone(); 92 - pg_config.host(&val); 110 + pg_config.postgres_host = val; 93 111 } 94 112 Err(_) => { 95 113 warn_elog!( ··· 98 116 ); 99 117 // Default to localhost if not set 100 118 uuu.1 = "localhost".to_string(); 101 - pg_config.host("localhost"); 119 + pg_config.postgres_host = "localhost".to_string(); 102 120 } 103 121 }; 104 122 match std::env::var("LUMINA_POSTGRES_PASSWORD") { 105 123 Ok(val) => { 106 - pg_config.password(&val); 124 + pg_config.postgres_password = Some(val); 107 125 } 108 126 Err(_) => { 109 127 warn_elog!( ··· 123 141 }; 124 142 125 143 // Create Postgres connection pool 126 - let pg_manager = PostgresConnectionManager::new(pg_config.clone(), NoTls); 127 - let pg_pool = Pool::builder().build(pg_manager).await?; 144 + let uri = format!( 145 + "postgres://{}{}@{}:{}/{}", 146 + pg_config.postgres_username, 147 + pg_config 148 + .postgres_password 149 + .as_deref() 150 + .map(|a| format!(":{}", a)) 151 + .unwrap_or_default(), 152 + pg_config.postgres_host, 153 + pg_config.postgres_port, 154 + pg_config.postgres_dbname 155 + ); 156 + let pg_pool = PgPool::connect(uri.as_str()).await?; 128 157 { 129 - let pg_conn = pg_pool.get().await?; 130 - pg_conn 131 - .batch_execute(include_str!("../../SQL/create_pg.sql")) 132 - .await?; 158 + // This is where previously the database schema was created if it did not exist, but now 159 + // we use sqlx and let it do that :) 160 + // pg_conn 161 + // .batch_execute(include_str!("../../SQL/create_pg.sql")) 162 + // .await?; 133 163 // Populate bloom filters 134 164 let mut redis_conn = redis_pool.get().await?; 135 165 let email_key = "bloom:email"; 136 166 let username_key = "bloom:username"; 137 167 138 - let rows = pg_conn 139 - .query("SELECT email, username FROM users", &[]) 140 - .await?; 141 - for row in rows { 142 - let email: String = row.get(0); 143 - let username: String = row.get(1); 168 + // (email, username) 169 + let users_and_emails = operations::list_users_and_emails(&pg_pool).await?; 170 + for (email, username) in users_and_emails { 144 171 let _: () = redis::cmd("BF.ADD") 145 172 .arg(email_key) 146 173 .arg(email) ··· 174 201 #[derive()] 175 202 pub enum DbConn { 176 203 /// The main database is a Postgres database in this variant. 177 - PgsqlConnection( 178 - Pool<PostgresConnectionManager<NoTls>>, 179 - Pool<RedisConnectionManager>, 180 - ), 204 + PgsqlConnection(PgPool, Pool<RedisConnectionManager>), 181 205 } 182 206 183 207 pub(crate) trait DatabaseConnections { ··· 189 213 190 214 /// Get a reference to the Postgres pool 191 215 /// This returns a clone of the pool without recreating it entirely, so it is cheap to call 192 - fn get_postgres_pool(&self) -> Pool<PostgresConnectionManager<NoTls>>; 216 + fn get_postgres_pool(&self) -> PgPool; 193 217 194 218 /// Recreate the database connection. 195 219 async fn recreate(&self) -> PgConn ··· 213 237 DbConn::PgsqlConnection(_, redis_pool) => redis_pool.clone(), 214 238 } 215 239 } 216 - fn get_postgres_pool(&self) -> Pool<PostgresConnectionManager<NoTls>> { 240 + fn get_postgres_pool(&self) -> PgPool { 217 241 match self { 218 - DbConn::PgsqlConnection(pg_pool, _) => pg_pool.clone(), 242 + DbConn::PgsqlConnection(pg_pool, _) => return pg_pool.clone(), 219 243 } 220 244 } 221 245 } ··· 225 249 self.redis_pool.clone() 226 250 } 227 251 228 - fn get_postgres_pool(&self) -> Pool<PostgresConnectionManager<NoTls>> { 252 + fn get_postgres_pool(&self) -> PgPool { 229 253 self.postgres_pool.clone() 230 254 } 231 255 ··· 239 263 /// Simplified type only accounting for the Postgres struct, since the enum adds some future flexibility, but also a lot of overhead. 240 264 /// If all goes well, this PgConn type will have replaced DbConn entirely after a few iterations of improvement over the years. 241 265 pub struct PgConn { 242 - pub(crate) postgres_pool: Pool<PostgresConnectionManager<NoTls>>, 266 + pub(crate) postgres_pool: PgPool, 243 267 pub(crate) redis_pool: Pool<RedisConnectionManager>, 244 268 } 245 269 ··· 409 433 410 434 Ok(()) 411 435 } 436 + 437 + mod operations { 438 + use super::*; 439 + use anyhow::Result; 440 + /// List all users and their emails from the database, used for populating bloom filters on 441 + ///startup 442 + /// 443 + /// Returns a vector of tuples containing the email and username of each user in the database: 444 + /// ```rust 445 + /// Vec<(String, String)> // (email, username) 446 + /// ``` 447 + pub async fn list_users_and_emails(pool: &PgPool) -> Result<Vec<(String, String)>> { 448 + let recs = sqlx::query!( 449 + r#" 450 + SELECT email, username 451 + FROM users 452 + "# 453 + ) 454 + .fetch_all(pool) 455 + .await?; 456 + let mut res = vec![]; 457 + for rec in recs { 458 + res.push((rec.email, rec.username)); 459 + } 460 + return Ok(res); 461 + } 462 + }
+1 -1
server/src/main.rs
··· 40 40 use tokio::sync::Mutex; 41 41 use uuid::Uuid; 42 42 mod user; 43 - use tokio_postgres as postgres; 43 + 44 44 struct AppState(Arc<InnerAppState>); 45 45 struct InnerAppState { 46 46 #[allow(dead_code)]