chore: merge cli with core
This commit is contained in:
parent
5833e8802c
commit
e8cce2fca5
8 changed files with 7 additions and 24 deletions
|
@ -1,5 +1,4 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"migra-core",
|
|
||||||
"migra-cli"
|
"migra-cli"
|
||||||
]
|
]
|
|
@ -10,8 +10,8 @@ name = "migra"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
migra-core = { path = '../migra-core' }
|
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
|
postgres = "0.19.0"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use migra_core::path::PathBuilder;
|
use crate::path::PathBuilder;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod database;
|
||||||
mod opts;
|
mod opts;
|
||||||
|
mod path;
|
||||||
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use migra_core::path::PathBuilder;
|
|
||||||
use opts::{AppOpt, ApplyCommandOpt, Command, MakeCommandOpt, StructOpt};
|
use opts::{AppOpt, ApplyCommandOpt, Command, MakeCommandOpt, StructOpt};
|
||||||
|
use path::PathBuilder;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -19,7 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Command::Apply(ApplyCommandOpt { file_name }) => {
|
Command::Apply(ApplyCommandOpt { file_name }) => {
|
||||||
let config = Config::read(opt.config)?;
|
let config = Config::read(opt.config)?;
|
||||||
|
|
||||||
let mut client = migra_core::database::connect(&config.database.connection)?;
|
let mut client = database::connect(&config.database.connection)?;
|
||||||
|
|
||||||
let file_path = PathBuilder::from(config.directory_path())
|
let file_path = PathBuilder::from(config.directory_path())
|
||||||
.append(file_name)
|
.append(file_name)
|
||||||
|
@ -28,7 +30,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
let content = fs::read_to_string(file_path)?;
|
let content = fs::read_to_string(file_path)?;
|
||||||
|
|
||||||
match migra_core::database::apply_sql(&mut client, &content) {
|
match database::apply_sql(&mut client, &content) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("File was applied successfully")
|
println!("File was applied successfully")
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,6 @@ impl<P: AsRef<Path>> From<P> for PathBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathBuilder {
|
impl PathBuilder {
|
||||||
pub fn new<P: AsRef<Path>>() -> Self {
|
|
||||||
PathBuilder {
|
|
||||||
buf: PathBuf::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn append<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
pub fn append<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
self.buf.push(path);
|
self.buf.push(path);
|
||||||
self
|
self
|
|
@ -1,8 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "migra-core"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
postgres = "0.19.0"
|
|
|
@ -1,4 +0,0 @@
|
||||||
#![deny(clippy::all)]
|
|
||||||
|
|
||||||
pub mod database;
|
|
||||||
pub mod path;
|
|
Reference in a new issue