Skip to content

Commit

Permalink
More work on the conversion to SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Apr 22, 2024
1 parent f474019 commit 1ee3917
Show file tree
Hide file tree
Showing 8 changed files with 4,254 additions and 4,305 deletions.
4 changes: 2 additions & 2 deletions bin/db
Expand Up @@ -8,7 +8,7 @@ check_vars

if [ $# -eq 0 ]
then
mysql -h"$TE_DB_HOST" -u"$TE_DB_USER" -p"$TE_DB_PASS" "$TE_DB_NAME"
sqlite3 "$TE_DB_FILE"
else
echo "$*" | mysql -t -h"$TE_DB_HOST" -u"$TE_DB_USER" -p"$TE_DB_PASS" "$TE_DB_NAME"
echo "$*" | sqlite3 "$TE_DB_FILE"
fi
11 changes: 5 additions & 6 deletions bin/dump_db
Expand Up @@ -6,10 +6,9 @@ dir=$(dirname "$0")

check_vars


dump_file="data/twittelection_dump.sql"

echo Dumping database
mysqldump --skip-extended-insert \
-h"$TE_DB_HOST" \
-P"${TE_PORT:-3306}" \
-u"$TE_DB_USER" \
-p"$TE_DB_PASS" \
"$TE_DB_NAME" > data/twittelection_dump.sql
echo ".tables" | sqlite3 "$TE_DB_FILE" | while read table; do echo "DROP TABLE IF EXISTS $table;"; done > "$dump_file"
echo ".dump" | sqlite3 "$TE_DB_FILE" >> "$dump_file"
9 changes: 3 additions & 6 deletions bin/dump_ddl
Expand Up @@ -6,10 +6,7 @@ dir=$(dirname "$0")

check_vars

ddl_file="data/twittelection_ddl.sql"

echo Dumping database DDL
mysqldump --skip-extended-insert -d \
-h"$TE_DB_HOST" \
-P"${TE_PORT:-3306}" \
-u"$TE_DB_USER" \
-p"$TE_DB_PASS" \
"$TE_DB_NAME" > data/twittelection_ddl.sql
echo ".schema" | sqlite3 "$TE_DB_FILE" > "$ddl_file"
3 changes: 2 additions & 1 deletion bin/dump_table
Expand Up @@ -6,4 +6,5 @@ then
exit 1
fi

mysqldump -u"$TE_DB_USER" -p"$TE_DB_PASS" -h"$TE_DB_HOST" "$TE_DB_NAME" --no-create-info "$1" > "db/$1.dat"
echo ".mode insert" > "db/$1.dat"
echo ".dump $1" | sqlite3 "$TE_DB_FILE" >> "db/$1.dat"
2 changes: 1 addition & 1 deletion bin/func_defs
@@ -1,7 +1,7 @@
#!/bin/bash

check_vars() {
declare -a vars=(TE_DB_HOST TE_DB_NAME TE_DB_USER TE_DB_PASS)
declare -a vars=(TE_DB_FILE)

for var_name in "${vars[@]}"
do
Expand Down
9 changes: 2 additions & 7 deletions bin/load_db
Expand Up @@ -6,11 +6,6 @@ dir=$(dirname "$0")

check_vars

echo Loading database
mysql \
-h"$TE_DB_HOST" \
-P"${TE_PORT:-3306}" \
-u"$TE_DB_USER" \
-p"$TE_DB_PASS" \
"$TE_DB_NAME" < data/twittelection_dump.sql

echo Loading database
sqlite3 "$TE_DB_FILE" < data/twittelection_dump.sql
37 changes: 37 additions & 0 deletions data/twittelection_ddl.sql
@@ -0,0 +1,37 @@
CREATE TABLE IF NOT EXISTS "candidate" (
"id" INTEGER PRIMARY KEY NOT NULL,
"yournextmp_id" int(11) NOT NULL,
"name" varchar(200) NOT NULL,
"twitter" varchar(200) DEFAULT NULL,
"party_id" int(11) NOT NULL,
"constituency_id" int(11) DEFAULT NULL,
"current_mp" int(11) NOT NULL DEFAULT 0,
"twitter_problem" smallint(6) NOT NULL DEFAULT 0,
FOREIGN KEY ("party_id") REFERENCES "party"("id"),
FOREIGN KEY ("constituency_id") REFERENCES "constituency"("id")
);
CREATE INDEX "party_id" ON "candidate" ("party_id");
CREATE INDEX "constituency_id" ON "candidate" ("constituency_id");
CREATE UNIQUE INDEX "yournextmp_id" ON "candidate" ("yournextmp_id");
CREATE TABLE IF NOT EXISTS "constituency" (
"id" INTEGER PRIMARY KEY NOT NULL,
"mapit_id" int(11) NOT NULL DEFAULT 0,
"demclub_id" varchar(20) DEFAULT NULL,
"name" varchar(200) NOT NULL,
"list_name" varchar(25) NOT NULL,
"list_id" varchar(20) DEFAULT NULL,
"candidates_updated_time" datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
"list_rebuilt_time" datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
"list_checked_time" datetime DEFAULT NULL
);
CREATE UNIQUE INDEX "mapit_id" ON "constituency" ("mapit_id");
CREATE TABLE IF NOT EXISTS "party" (
"id" INTEGER PRIMARY KEY NOT NULL,
"yournextmp_id" int(11) NOT NULL,
"name" varchar(200) NOT NULL,
"list_name" varchar(25) NOT NULL DEFAULT '',
"list_id" varchar(20) DEFAULT NULL,
"candidates_updated_time" datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
"list_rebuilt_time" datetime NOT NULL DEFAULT '2000-01-01 00:00:00'
);
CREATE UNIQUE INDEX "yournextmp_id02" ON "party" ("yournextmp_id");
8,484 changes: 4,202 additions & 4,282 deletions data/twittelection_dump.sql

Large diffs are not rendered by default.

0 comments on commit 1ee3917

Please sign in to comment.