summaryrefslogtreecommitdiffhomepage
path: root/src/dbx
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbx')
-rw-r--r--src/dbx/.gitignore1
-rw-r--r--src/dbx/db.go23
-rw-r--r--src/dbx/sql/000-genesis.sql29
3 files changed, 22 insertions, 31 deletions
diff --git a/src/dbx/.gitignore b/src/dbx/.gitignore
new file mode 100644
index 0000000..d14a707
--- /dev/null
+++ b/src/dbx/.gitignore
@@ -0,0 +1 @@
+sql/last.sql \ No newline at end of file
diff --git a/src/dbx/db.go b/src/dbx/db.go
index e0c8e30..3a6f24a 100644
--- a/src/dbx/db.go
+++ b/src/dbx/db.go
@@ -95,9 +95,17 @@ func applyMigrations(dir string) error {
return err
}
- scripts := []string{}
+ var (
+ last string
+ scripts []string
+ )
+
for _, f := range files {
- scripts = append(scripts, f.Name())
+ if n := f.Name(); n == "last.sql" {
+ last = n
+ } else {
+ scripts = append(scripts, f.Name())
+ }
}
sort.Strings(scripts)
@@ -132,6 +140,17 @@ func applyMigrations(dir string) error {
log.Printf("Applied database migration ‘%s’", f)
}
+ if last != "" {
+ qry, err := migrations.ReadFile(filepath.Join(dir, last))
+ if err != nil {
+ return err
+ }
+ if _, err := db.Exec(string(qry)); err != nil {
+ return fmt.Errorf("error in ‘%s’: %w", last, err)
+ }
+ log.Printf("Ran ‘%s’\n", last)
+ }
+
return nil
}
diff --git a/src/dbx/sql/000-genesis.sql b/src/dbx/sql/000-genesis.sql
index 6daad31..327ff58 100644
--- a/src/dbx/sql/000-genesis.sql
+++ b/src/dbx/sql/000-genesis.sql
@@ -37,35 +37,6 @@ CREATE TABLE mintages_c (
reference TEXT
);
--- TODO: Remove dummy data
-INSERT INTO mintages_s (
- country,
- type,
- year,
- mintmark,
- [€0,01],
- [€0,02],
- [€0,05],
- [€0,10],
- [€0,20],
- [€0,50],
- [€1,00],
- [€2,00],
- reference
-) VALUES
- ("ad", 0, 2014, NULL, 60000, 60000, 860000, 860000, 860000, 340000, 511843, 360000, NULL),
- ("ad", 0, 2015, NULL, 0, 0, 0, 0, 0, 0, 0, 1072400, NULL),
- ("ad", 0, 2016, NULL, 0, 0, 0, 0, 0, 0, 2339200, 0, NULL),
- ("ad", 0, 2017, NULL, 2582395, 1515000, 2191421, 1103000, 1213000, 968800, 17000, 794588, NULL),
- ("ad", 0, 2018, NULL, 2430000, 2550000, 1800000, 980000, 1014000, 890000, 0, 868000, NULL),
- ("ad", 0, 2019, NULL, 2447000, 1727000, 2100000, 1610000, 1570000, 930000, 0, 1058310, NULL),
- ("ad", 0, 2020, NULL, 0, 0, 0, 860000, 175000, 740000, 0, 1500000, NULL),
- ("ad", 0, 2021, NULL, 200000, 700000, 0, 1400000, 1420000, 600000, 50000, 1474500, NULL),
- ("ad", 0, 2022, NULL, 700000, 450000, 400000, 700000, 700000, 380000, 0, 1708000, NULL),
- ("ad", 0, 2023, NULL, 0, 0, 0, 0, 0, 0, 0, 2075250, NULL),
- ("ad", 0, 2024, NULL, 0, 900300, 1950000, 1000000, 700000, 500000, 1050000, 1601200, NULL),
- ("ad", 0, 2025, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-
CREATE TABLE users (
email TEXT COLLATE BINARY,
username TEXT COLLATE BINARY,