Skip to content

Commit d8eca47

Browse files
committed
update database migration toolkit
Signed-off-by: keinsell <[email protected]>
1 parent aff24dc commit d8eca47

33 files changed

+520
-561
lines changed

.gitattributes

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
flake.lock linguist-generated=true
2-
src/lib/migration/sql/*.sql linguist-detectable linguist-language=sql
3-
src/lib/migration/sql/2_add_substance_data.sql binary linguist-vendored
2+
src/lib/migration/migrations/*.sql linguist-detectable linguist-language=sql
3+
src/lib/migration/sql/20250101000002_import_substance.sql binary linguist-vendored
44
docs/*.md linguist-detectable

.idea/dataSources.xml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cargo-features = ["edition2024"]
44
name = "neuronek"
55
description = "🧬 Intelligent dosage tracker application for monitoring supplements, nootropics and psychoactive substances along with their long-term influence on one's mind and body."
66
authors = ["Jakub Olan <[email protected]>"]
7-
version = "0.0.0-dev.5"
7+
version = "0.0.0-dev.6"
88
edition = "2024"
99
repository = "https://github.com/keinsell/neuronek"
1010

@@ -28,25 +28,19 @@ serde = { version = "1.0.216", features = ["derive", "std", "unstable"] }
2828
lazy_static = "1.5.0"
2929
figlet-rs = "0.1.5"
3030
serde_json = "1.0.133"
31-
chrono ={version = "0.4.39", features = ["std", "serde", "iana-time-zone"]}
31+
chrono = { version = "0.4.39", features = ["std", "serde", "iana-time-zone"] }
3232
log = { version = "0.4.22", features = ["serde", "kv"] }
3333
measurements = { version = "0.11.0", features = ["std", "serde", "from_str", "regex"] }
3434
pubchem = "0.1.1"
3535
tabled = "0.17.0"
3636
rust-embed = "8.5.0"
37-
predicates = "3.1.2"
3837
assert_cmd = "2.0.16"
3938
logforth = "0.19.0"
40-
bupropion = "0.0.20"
4139
typed-builder = "0.20.0"
4240
date_time_parser = "0.2.0"
43-
chrono-humanize = "0.2.3"
4441
chrono-english = "0.1.7"
4542
clap-verbosity-flag = "3.0.1"
46-
clap_autocomplete = "0.4.2"
47-
tantivy = "0.22.0"
4843
clap_complete = "4.5.40"
49-
clap_complete_command = "0.6.1"
5044
atty = "0.2.14"
5145
[dependencies.sea-orm-migration]
5246
version = "1.1.0"
@@ -64,4 +58,4 @@ atty = "0.2"
6458

6559
[profile.dist]
6660
inherits = "release"
67-
lto = "fat"
61+
lto = "fat"

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ their long-term influence on one's mind and body.
77

88
## About
99

10-
Neuronek is an intelligent dosage tracking application designed to monitor and log the use of supplements, nootropics, and
10+
Neuronek is an intelligent dosage tracking application designed to monitor and log the use of supplements, nootropics,
11+
and
1112
psychoactive substances. By recording and analyzing ingestion, it helps users better understand the long-term effects
1213
of these compounds on their physical and mental health.
1314

14-
### Motivation
15-
16-
As pretty irresponsible autist I do not count times when I was literally forgetting to take a meds, skipped days, took twice, took too late and so on.
17-
1815
## Getting Started
1916

2017
### Installation
@@ -65,7 +62,7 @@ After installation, you can start using the application by running the `psylog`
6562
application provides a command-line interface (CLI) for interacting with its features and functionalities.
6663

6764
```bash
68-
psylog --help
65+
neuronek --help
6966
```
7067

7168
## Features
@@ -233,7 +230,8 @@ friendly human interface.
233230

234231
*Roadmap is a subject to change and one that is presented here is a high-level overview of direction of the project.*
235232

236-
neuronek is an ongoing project with many planned features and improvements. Some of the key areas of development include:
233+
neuronek is an ongoing project with many planned features and improvements. Some of the key areas of development
234+
include:
237235

238236
- **Journaling**: A user-friendly interface for creating and managing journal entries related to ingestions, thoughts,
239237
and experiences.
@@ -242,10 +240,10 @@ neuronek is an ongoing project with many planned features and improvements. Some
242240
- **Desktop/Mobile Application**
243241
- **Cloud Sync**
244242

245-
246243
## Contributing
247244

248-
Project do not expect any external contribution. If you want to contribute, please contact me directly via [[email protected]]() and we can discuss the project together and move code to
245+
Project do not expect any external contribution. If you want to contribute, please contact me directly
246+
via [[email protected]]() and we can discuss the project together and move code to
249247
organization out of my profile.
250248

251249
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

docs/JOURNAL.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Project's Journal
2+
3+
## 2025
4+
5+
### January
6+
7+
#### 01
8+
9+
- **Spent 4 hours** working on implementing a migration toolkit with `Atlas`, only to realize that it’s not really
10+
compatible with code-first ORMs like `SeaORM` and adds more complexity than just writing migrations manually in Rust.
11+
Well, these things happen. For now, it’s fine for the current scope, but I’ll likely remove `Atlas` in the future. It
12+
seems better suited for cloud-native applications, whereas for our **local-first application**, tools like `Sqitch`
13+
and `Prisma` seem like more fitting options. **Atlas** does have its use cases, but it’s not a good fit here.
14+
15+
- **Cleaned up the database schema**—we had a lot of unnecessary, chemical-specific data that wasn’t adding any real
16+
value to the project. Now, we’re only storing the essential information, which keeps the database clean and focused,
17+
without unnecessary bloat.

justfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
default:
22
@just --list
33

4+
install-requirements:
5+
cargo install cargo-machete sccache
6+
47
lint:
58
cargo lint
69

@@ -14,6 +17,7 @@ format:
1417
fix:
1518
@just format
1619
cargo fix
20+
cargo-machete --fix
1721

1822
build:
1923
cargo build

src/command/substance/get_substance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl CommandHandler for GetSubstance
3535
{
3636
let substances = substance::Entity::find()
3737
.filter(substance::Column::CommonNames.contains(&self.substance_name.to_lowercase()))
38-
.order_by_asc(substance::Column::SystematicName)
38+
.order_by_asc(substance::Column::Name)
3939
.all(context.database_connection)
4040
.await
4141
.into_diagnostic()?;

src/lib/migration/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Running Migrator CLI
1+
# Database Management
2+
3+
This directory introduces you to management of database schema in application.
4+
5+
```bash
6+
curl -sSf https://atlasgo.sh | sh -s -- --community
7+
```
28

39
- Generate a new migration file
410
```sh

src/lib/migration/justfile

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
DEFAULT_DATABASE_CONNECTION_URI := "sqlite:///tmp/neuronek.sqlite"
2+
schema_format := "{{ sql . }}"
3+
dev_db := "sqlite://dev?mode=memory"
4+
migration_dir := "./migrations"
5+
schema_file := "schema.sql"
6+
7+
inspect connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
8+
atlas schema inspect -u {{ connection_uri }}
9+
10+
pull connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
11+
atlas schema inspect -u "{{ connection_uri }}" --format '{{ schema_format }}' > {{ schema_file }}
12+
13+
push connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
14+
atlas schema apply \
15+
-u "{{ connection_uri }}" \
16+
--to file://schema.sql \
17+
--dev-url "{{ dev_db }}"
18+
19+
plan migration_name connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
20+
@just hash
21+
atlas migrate diff {{ migration_name }} \
22+
--dir "file://{{ migration_dir }}" \
23+
--to "file://{{ schema_file }}" \
24+
--dev-url "{{ dev_db }}"
25+
26+
create migration_name:
27+
atlas migrate new {{ migration_name }}
28+
29+
up connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
30+
@just hash
31+
atlas migrate apply \
32+
--url "{{ connection_uri }}"
33+
34+
hash:
35+
atlas migrate hash --dir="file://{{ migration_dir }}"
36+
37+
fresh:
38+
@just hash
39+
@just clean
40+
@just up
41+
@just pull
42+
43+
clean connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
44+
atlas schema clean -u "{{ connection_uri }}" --auto-approve
45+
46+
baseline connection_uri=DEFAULT_DATABASE_CONNECTION_URI:
47+
atlas migrate diff baseline \
48+
--dir "file://{{ migration_dir }}" \
49+
--dev-url "{{ dev_db }}" \
50+
--to "{{ connection_uri }}" \
51+
52+
generate:
53+
sea-orm-cli generate entity \
54+
--compact-format \
55+
--ignore-tables=seaql_migrations,atlas_schema_revisions \
56+
--output-dir="./../orm" \
57+
-u="{{ DEFAULT_DATABASE_CONNECTION_URI }}" \
58+
--with-serde=both \
59+
--with-copy-enums

src/lib/migration/m20020101_000002_create_database_schema.rs

-17
This file was deleted.

src/lib/migration/m20220101_000001_create_table.rs

-61
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Create "ingestion" table
2+
CREATE TABLE `ingestion`
3+
(
4+
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
5+
`substance_name` varchar NOT NULL,
6+
`route_of_administration` varchar NOT NULL,
7+
`dosage` float NOT NULL,
8+
`ingested_at` datetime_text NOT NULL,
9+
`updated_at` datetime_text NOT NULL,
10+
`created_at` datetime_text NOT NULL
11+
);
12+
-- Create "seaql_migrations" table
13+
CREATE TABLE IF NOT EXISTS `seaql_migrations`
14+
(
15+
`version` varchar NOT NULL,
16+
`applied_at` bigint NOT NULL,
17+
PRIMARY KEY (`version`)
18+
);

0 commit comments

Comments
 (0)