Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carbondb unique #877

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions docker/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ CREATE TABLE carbondb_energy_data_day (
co2_sum FLOAT,
carbon_intensity_avg FLOAT,
record_count INT,

created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone
);
Expand All @@ -378,10 +377,7 @@ CREATE TRIGGER carbondb_energy_data_day_moddatetime
CREATE INDEX idx_carbondb_hour_company ON carbondb_energy_data_day(company);
CREATE INDEX idx_carbondb_hour_machine ON carbondb_energy_data_day(machine);
CREATE INDEX idx_carbondb_hour_project ON carbondb_energy_data_day(project);


ALTER TABLE IF EXISTS public.carbondb_energy_data_day
ADD CONSTRAINT unique_machine_project_date UNIQUE (machine, date);
CREATE UNIQUE INDEX unique_entry ON carbondb_energy_data_day (type, company, machine, project, tags, date) NULLS NOT DISTINCT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding eh company and the project? Initially the idea was that you only need a machine. But I think we are going to rework this anyway


CREATE TABLE ip_data (
ip_address INET,
Expand Down
3 changes: 3 additions & 0 deletions migrations/2024_08_26_carbondb_unique.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE carbondb_energy_data_day drop constraint unique_machine_project_date;
TRUNCATE carbondb_energy_data_day;
CREATE UNIQUE INDEX unique_entry ON carbondb_energy_data_day (type, company, machine, project, tags, date) NULLS NOT DISTINCT;
2 changes: 1 addition & 1 deletion tools/carbondb_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def compress_data():
e.project,
e.tags,
DATE_TRUNC('day', TO_TIMESTAMP(e.time_stamp / 1000000))
ON CONFLICT (machine, date) DO UPDATE
ON CONFLICT (type, company, machine, project, tags, date) DO UPDATE
SET
energy_sum = EXCLUDED.energy_sum,
co2_sum = EXCLUDED.co2_sum,
Expand Down
Loading