Skip to content

Commit

Permalink
Remove Cycle table
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcaunt committed Sep 30, 2021
1 parent 90ec714 commit 96097e5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 40 deletions.
1 change: 0 additions & 1 deletion CSV_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def load_csv(tablename):
await loader.employer(load_csv("employer"))
await loader.user(load_csv("user"))
await loader.instrument(load_csv("instrument"))
await loader.cycle(load_csv("cycle"))
await loader.proposal(load_csv("proposal"))
await loader.experiment(load_csv("experiment"))
await loader.experiment_user(load_csv("experiment_user"))
Expand Down
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.0.2 30/09/2021
================
* Remove Cycle table

2.0.1 16/07/2021
================

Expand Down
28 changes: 2 additions & 26 deletions loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,11 @@ async def clean(self):
await self.conn.execute("delete from experiment_user;")
await self.conn.execute("delete from experiment where id not in (select distinct experiment_id from instance_experiment);")
await self.conn.execute("delete from proposal where id not in (select distinct proposal_id from experiment);")
await self.conn.execute("delete from cycle where id not in (select distinct cycle_id from experiment)")
await self.conn.execute("delete from instrument where id not in (select distinct instrument_id from experiment);")
await self.conn.execute("delete from users where id not in (select distinct user_id from instance_command union select distinct user_id from instance_member union select distinct user_id from instance_session_member union select distinct user_id from user_role);")
await self.conn.execute("delete from employer where id not in (select distinct affiliation_id from users);")
print("everything cleaned")

async def cycle(self, cycles):
async with self.conn.transaction():
inserted = 0
updated = 0
total_lines = 0
for cycle in cycles:
res = await self.conn.execute(
"""INSERT INTO cycle (id, name, start_date, end_date)
VALUES ($1, $2, $3, $4)
ON CONFLICT (id) DO UPDATE
SET name = $2, start_date=$3, end_date=$4""",
int(cycle['id']),
cycle['name'],
cycle['start_date'],
cycle['end_date']
)
response_parsed = self.parse_response_reg.match(res)
inserted += int(response_parsed.group(1))
updated += int(response_parsed.group(2))
total_lines += 1
print("Cycle : INSERT {0} UPDATE {1} TOTAL {2}".format(inserted, updated, total_lines))

async def employer(self, employers):
async with self.conn.transaction():
inserted = 0
Expand Down Expand Up @@ -79,13 +56,12 @@ async def experiment(self, experiments):
total_lines = 0
for experiment in experiments:
res = await self.conn.execute(
"""INSERT INTO experiment (id, proposal_id, cycle_id, instrument_id)
"""INSERT INTO experiment (id, proposal_id, instrument_id)
VALUES ($1, $2, $3, $4)
ON CONFLICT (id) DO UPDATE
SET proposal_id = $2, cycle_id=$3, instrument_id=$4""",
SET proposal_id = $2, instrument_id=$4""",
experiment['id'],
int(experiment['proposal_id']),
int(experiment['cycle_id']),
int(experiment['instrument_id'])
)
response_parsed = self.parse_response_reg.match(res)
Expand Down
13 changes: 0 additions & 13 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ create table if not exists configuration
value varchar(8192) not null
);

create table if not exists cycle
(
id bigint not null
constraint cycle_pkey
primary key,
end_date timestamp not null,
name varchar(100) not null,
start_date timestamp not null
);

create table if not exists employer
(
id bigint not null
Expand Down Expand Up @@ -206,9 +196,6 @@ create table if not exists experiment
id varchar(32) not null
constraint experiment_pkey
primary key,
cycle_id bigint not null
constraint fk_cycle_id
references cycle,
instrument_id bigint not null
constraint fk_instrument_id
references instrument,
Expand Down

0 comments on commit 96097e5

Please sign in to comment.