aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--migrations/00000000000000_diesel_initial_setup/down.sql11
-rw-r--r--migrations/00000000000000_diesel_initial_setup/up.sql (renamed from src/util/fresh.sql)11
-rw-r--r--src/main.rs4
-rw-r--r--src/schema.rs66
5 files changed, 82 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 5f84f27..9fe3b61 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,9 +3,7 @@
!.env.sample
Cargo.lock
-migrations/
target/
-
*.out
*~
**/*.rs.bk \ No newline at end of file
diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql
new file mode 100644
index 0000000..74a7b3d
--- /dev/null
+++ b/migrations/00000000000000_diesel_initial_setup/down.sql
@@ -0,0 +1,11 @@
+-- down.sql: Destroy initial database migration for AO
+DROP FUNCTION IF EXISTS public.GETDATE();
+
+DROP TABLE users;
+DROP TABLE activation_keys;
+DROP TABLE games;
+DROP TABLE allegiances;
+DROP TABLE regions;
+DROP TABLE nationstates;
+DROP TABLE borders;
+DROP TABLE games_nationstates; \ No newline at end of file
diff --git a/src/util/fresh.sql b/migrations/00000000000000_diesel_initial_setup/up.sql
index f39b360..83a7869 100644
--- a/src/util/fresh.sql
+++ b/migrations/00000000000000_diesel_initial_setup/up.sql
@@ -1,9 +1,4 @@
- -- fresh.sql: SQL script that creates the tables used by AO
- -- please drop all tables in db before initiating unless told otherwise
-
- -- uncomment the following two lines to automatically drop all tables
---DROP SCHEMA "public" CASCADE;
---CREATE SCHEMA "public";
+ -- up.sql: Initial database migration for AO
CREATE OR REPLACE FUNCTION public.GETDATE() RETURNS TIMESTAMPTZ
STABLE LANGUAGE SQL AS 'SELECT NOW()';
@@ -14,9 +9,7 @@ CREATE TABLE users (
email VARCHAR(40) UNIQUE NOT NULL,
firstname VARCHAR(20) NOT NULL,
lastname VARCHAR(20) NOT NULL,
- password VARCHAR(255) NOT NULL, -- intend to use bcrypt hash through PHP
- games INTEGER DEFAULT 0, -- simple tracking statistics
- wins INTEGER DEFAULT 0, -- "
+ password VARCHAR(255) NOT NULL, -- intend to use bcrypt hash
joindate DATE DEFAULT GETDATE(),
activated BIT(1) DEFAULT B'0', -- see activation_keys table
PRIMARY KEY (userid)
diff --git a/src/main.rs b/src/main.rs
index 4c2c020..157d035 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,9 +7,11 @@ extern crate error_chain;
extern crate actix;
extern crate actix_web;
extern crate env_logger;
+#[macro_use]
extern crate diesel;
-mod errors;
+pub mod errors;
+pub mod schema;
use actix_web::{middleware, server, App, HttpRequest};
use diesel::prelude::*;
diff --git a/src/schema.rs b/src/schema.rs
new file mode 100644
index 0000000..2f0daba
--- /dev/null
+++ b/src/schema.rs
@@ -0,0 +1,66 @@
+table! {
+ users(userid) {
+ userid -> Serial,
+ email -> VarChar,
+ firstname -> VarChar,
+ lastname -> VarChar,
+ password -> VarChar,
+ joindate -> Date,
+ activated -> Bool,
+ }
+}
+table! {
+ activation_keys(code) {
+ code -> VarChar,
+ userid -> Serial,
+ }
+}
+table! {
+ games(gameid) {
+ gameid -> Serial,
+ title -> VarChar,
+ gametypeid -> Serial,
+ players -> SmallInt,
+ waitfor -> Integer,
+ lastturn -> Date,
+ gamestate -> Integer,
+ }
+}
+table! {
+ allegiances(gameid, userid) {
+ gameid -> Serial,
+ userid -> Serial,
+ allegiance -> VarChar,
+ ordernum -> SmallInt,
+ playing -> SmallInt,
+ }
+}
+table! {
+ regions(regionid) {
+ regionid -> Serial,
+ name -> VarChar,
+ abbreviation -> Char,
+ bonus -> Integer,
+ }
+}
+table! {
+ nationstates(nationid) {
+ nationid -> Serial,
+ regionid -> Serial,
+ name -> VarChar,
+ abbreviation -> Char,
+ }
+}
+table! {
+ borders(nationid, borderid) {
+ nationid -> Serial,
+ borderid -> Serial,
+ }
+}
+table! {
+ regions_nationstates(gameid, nationid) {
+ gameid -> Serial,
+ nationid -> Serial,
+ userid -> Serial,
+ }
+} \ No newline at end of file