Compare commits

..

No commits in common. "c5c8f27ae67eb97c2b625012c7dc78afe1bd0fd7" and "e8ff6960067aa57e9bcaf3bff6bc1618fcbb9125" have entirely different histories.

2 changed files with 15 additions and 22 deletions

View File

@ -8,10 +8,11 @@ CREATE TABLE IF NOT EXISTS users (
email VARCHAR NOT NULL,
password VARCHAR NOT NULL,
role INTEGER DEFAULT 1 NOT NULL,
UNIQUE(username),
UNIQUE(email)
UNIQUE(username, email)
);
CREATE UNIQUE INDEX ux_username ON users(username);
CREATE TABLE IF NOT EXISTS links (
id INTEGER PRIMARY KEY NOT NULL,
title VARCHAR NOT NULL,

View File

@ -5,7 +5,6 @@ use clap::{
use dotenv::dotenv;
use sqlx::{migrate::Migrator, Pool, Sqlite};
use std::{
fs::File,
io::{self, BufRead, Write},
path::PathBuf,
};
@ -214,16 +213,14 @@ async fn parse_args_to_config(config: ArgMatches<'_>, log: Logger) -> ServerConf
pub(crate) async fn setup() -> Result<Option<crate::ServerConfig>, ServerError> {
dotenv().ok();
// initiallize the logger
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
let log = slog::Logger::root(drain, slog_o!("name" => "Pslink"));
// Print launch info
slog_info!(log, "Launching Pslink a 'Private short link generator'");
slog_info!(log, "logging initialized");
slog_info!(log, ".env file setup, logging initialized");
let app = generate_cli();
@ -239,7 +236,6 @@ pub(crate) async fn setup() -> Result<Option<crate::ServerConfig>, ServerError>
.parse::<PathBuf>()
.expect("Failed to parse Database path.");
if !db.exists() {
if config.subcommand_matches("migrate-database").is_none() {
let msg = format!(
concat!(
"Database not found at {}!",
@ -251,10 +247,6 @@ pub(crate) async fn setup() -> Result<Option<crate::ServerConfig>, ServerError>
slog_error!(log, "{}", msg);
eprintln!("{}", msg);
return Ok(None);
}
// create an empty database file the if above makes sure that this file does not exist.
File::create(db)?;
};
let server_config: crate::ServerConfig = parse_args_to_config(config.clone(), log).await;