-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export timestamps to SQL for migration (#319)
- Loading branch information
Showing
10 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,8 @@ nsi.allowed-requesters=urn:ogf:network:surfnet.nl:1990:nsa:nsi-requester | |
nsi.nsa-name=Nsa Name | ||
nsi.nsa-contact=Evangelos Chaniotakis,[email protected] | ||
nsi.nsa-location=37.876,-122.253 | ||
|
||
nsi.peerings=nada | ||
nsi.peerings=./config/nsi-peerings.json | ||
nsi.filter=./config/nsi-filter.json | ||
|
||
slack.enable=false | ||
slack.channel=oscars-playground | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"foo" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
dump_cmd = "pg_dump -f oscars.sql.bak -C -d oscars_backend" | ||
|
||
restore_command = "psql < oscars.sql.bak" | ||
|
||
drop_everything = "dropdb oscars_backend" | ||
|
||
import = "psql -d oscars_backend -f timestamps.sql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
alter table held drop column expiration; | ||
alter table held add column expiration timestamp; | ||
|
||
alter table router_command_history drop column date; | ||
alter table router_command_history add column date timestamp; | ||
|
||
alter table version drop column updated; | ||
alter table version add column updated timestamp; | ||
|
||
|
||
alter table schedule drop column beginning; | ||
alter table schedule drop column ending; | ||
|
||
alter table schedule add column beginning timestamp; | ||
alter table schedule add column ending timestamp; | ||
|
||
alter table event_log drop column created; | ||
alter table event_log drop column archived; | ||
|
||
alter table event_log add column created timestamp; | ||
alter table event_log add column archived timestamp; | ||
|
||
alter table event drop column at; | ||
alter table event add column at timestamp; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
migration/src/main/java/net/es/oscars/timefix/TimestampExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.es.oscars.timefix; | ||
|
||
import net.es.oscars.pss.ent.RouterCommandHistory; | ||
import net.es.oscars.resv.db.CommandHistoryRepository; | ||
import net.es.oscars.resv.db.LogRepository; | ||
import net.es.oscars.resv.db.ScheduleRepository; | ||
import net.es.oscars.resv.ent.Event; | ||
import net.es.oscars.resv.ent.EventLog; | ||
import net.es.oscars.resv.ent.Schedule; | ||
import net.es.oscars.topo.db.VersionRepository; | ||
import net.es.oscars.topo.ent.Version; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.io.*; | ||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
@Component | ||
public class TimestampExporter { | ||
@Autowired | ||
private CommandHistoryRepository historyRepo; | ||
@Autowired | ||
private VersionRepository versionRepo; | ||
|
||
@Autowired | ||
private ScheduleRepository schedRepo; | ||
|
||
|
||
@Autowired | ||
private LogRepository logRepo; | ||
|
||
private String i2p(Instant when) { | ||
if (when.equals(Instant.MAX)) { | ||
return "null"; | ||
} | ||
return "to_timestamp("+when.getEpochSecond()+")"; | ||
} | ||
|
||
@Transactional | ||
public void export() throws FileNotFoundException { | ||
PrintWriter out = new PrintWriter("timestamps.sql"); | ||
|
||
List<RouterCommandHistory> rch = historyRepo.findAll(); | ||
|
||
for (RouterCommandHistory rc : rch) { | ||
String sql = "UPDATE router_command_history SET date = "+i2p(rc.getDate())+" WHERE id = "+rc.getId()+";"; | ||
out.println(sql); | ||
} | ||
|
||
List<Version> versions = versionRepo.findAll(); | ||
|
||
for (Version v : versions) { | ||
String sql = "UPDATE version SET updated = "+i2p(v.getUpdated())+" WHERE id = "+v.getId()+";"; | ||
out.println(sql); | ||
} | ||
|
||
|
||
List<Schedule> schedules = schedRepo.findAll(); | ||
|
||
for (Schedule s : schedules) { | ||
String sql = "UPDATE schedule SET beginning = "+i2p(s.getBeginning())+", ending="+i2p(s.getEnding())+" WHERE id = "+s.getId()+";"; | ||
out.println(sql); | ||
} | ||
|
||
|
||
List<EventLog> logs = logRepo.findAll(); | ||
|
||
for (EventLog el : logs) { | ||
String sql = "UPDATE event_log SET archived = "+i2p(el.getArchived())+", created = "+i2p(el.getCreated())+" WHERE id = "+el.getId()+";"; | ||
out.println(sql); | ||
|
||
for (Event event : el.getEvents()) { | ||
String evsql = "UPDATE event SET at = "+i2p(event.getAt())+" WHERE id = "+event.getId()+";"; | ||
out.println(evsql); | ||
} | ||
} | ||
out.close(); | ||
} | ||
|
||
} |