Skip to content

Commit

Permalink
Added support for running migrations on startup. Started a dockerfile…
Browse files Browse the repository at this point in the history
…. Published the modified dep crates to Github.
  • Loading branch information
golddranks committed Nov 17, 2016
1 parent dc61387 commit a3af60d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 28 deletions.
39 changes: 19 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ diesel_codegen = {version = "0.8", default-features = false, features = ["postgr
dotenv = "0.8"
dotenv_macros = "0.9"
rust-crypto = "0.2"
error-chain = { path = "../error-chain" }
error-chain = { git = "https://github.com/golddranks/error-chain.git", branch = "tweaks_for_ganbare"}
clap = "2"
chrono = { version = "0.2", features = ["rustc-serialize"]}
rpassword = "0.2"
rand = "0.3"
rustc-serialize = "0.3"
binary_macros = "0.1"
data-encoding = "1.1"
pencil = { path = "../pencil" }
pencil = { git = "https://github.com/golddranks/pencil", branch = "modifications_for_ganbare" }
hyper = "0.9"
env_logger = "0.3"
log = "*"
lazy_static = "*"
time = "*"
lettre = "0.6"
handlebars = "*"
mime = { path = "../mime.rs"}
mime = "*"
mime_multipart = "*"
unicode-normalization = "*"
tempdir = "0.3"
regex = "0.1"

[replace]
"mime:0.2.2" = { path = "../mime.rs"}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM liuchong/rustup:nightly
MAINTAINER Pyry Kontio <[email protected]>

RUN rustup install nightly-2016-11-06

RUN rustup default nightly-2016-11-06

RUN apt-get update && \
apt-get install -y git

WORKDIR /opt

RUN git clone https://github.com/golddranks/ganbare.git

WORKDIR /opt/ganbare

RUN cargo build --release

ENV GANBARE_DATABASE_URL=postgres://drasa@localhost/ganbare_testing
ENV GANBARE_BUILDTIME_PEPPER=4l1S1zMc0sqltaga/plxvzHcq0z+gQI5n7DL53jjy9E=
ENV GANBARE_RUNTIME_PEPPER=4Y23isyrgd9ML/jJonemXNL0PnbMyerqnejHPBnDLaY=
ENV GANBARE_SERVER_BINDING=localhost:8080
ENV GANBARE_SITE_DOMAIN=testing.ganba.re
ENV GANBARE_EMAIL_DOMAIN=testing.ganba.re

EXPOSE 8080
3 changes: 3 additions & 0 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,9 @@ fn post_question(req: &mut Request) -> PencilResult {

fn main() {
dotenv().ok();

ganbare::run_db_migrations().expect("Migration error! Check the database!");

let mut app = Pencil::new(".");
app.register_template("hello.html");
app.register_template("main.html");
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod errors {
::std::num::ParseFloatError, ParseFloatError;
::std::io::Error, StdIoError;
::diesel::result::Error, DieselError;
::diesel::migrations::RunMigrationsError, DieselMigrationError;
::pencil::PencilError, PencilError;
}
errors {
Expand Down Expand Up @@ -106,6 +107,12 @@ pub mod errors {

use errors::*;

pub fn run_db_migrations() -> Result<()> {
let conn = db_connect()?;
diesel::migrations::run_pending_migrations(&conn)?;
Ok(())
}

pub fn db_connect() -> Result<PgConnection> {
dotenv().ok();
let database_url = env::var("GANBARE_DATABASE_URL")
Expand Down
2 changes: 1 addition & 1 deletion src/ts/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function drawList(nugget_resp, bundle_resp) {
data: JSON.stringify(data),
success: function(resp) {
c_item.remove();
createQuestionEntry(resp);
createQuestionEntry(resp, 2);
},
});
});
Expand Down
3 changes: 1 addition & 2 deletions static/ts/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ $(function () {
type: "POST",
data: JSON.stringify(data),
success: function (resp) {
console.log(resp);
c_item.remove();
createQuestionEntry(resp);
createQuestionEntry(resp, 2);
}
});
});
Expand Down

0 comments on commit a3af60d

Please sign in to comment.