Skip to content

Commit

Permalink
feat: first migration
Browse files Browse the repository at this point in the history
  • Loading branch information
stefa168 committed Nov 26, 2023
1 parent 54b5078 commit d50f8ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions migrations/0001_messages_and_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- First the table that contains the raw messages. Useful for future retrofit.
create table if not exists inverter_messages
(
id serial
constraint inverter_messages_pk
primary key,
raw bytea not null,
type text not null,
header bytea not null,
time timestamp with time zone
);

-- Now the table that holds all the extracted data from the raw messages.
create table if not exists message_data
(
message_id integer not null
constraint message_data_inverter_messages_id_fk
references inverter_messages,
key text not null,
value text,
constraint message_data_pk
primary key (message_id, key)
);

create index if not exists message_data_key_index
on message_data (key);

create index if not exists message_data_message_id_index
on message_data (message_id);

3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ async fn main() -> Result<()> {
.await
.expect_or_log("Failed to connect to the Database");

Check warning on line 89 in src/main.rs

View workflow job for this annotation

GitHub Actions / Cargo format

Diff in /home/runner/work/growatt_server/growatt_server/src/main.rs

let migrator = sqlx::migrate!("./migrations");
migrator.run(&db_pool).await.expect_or_log("Failed migrating the database to the latest version");

if config.inverters_dir.is_none() {
info!("No inverters path specified. Using default");
}
Expand Down

0 comments on commit d50f8ed

Please sign in to comment.