Change env schema loading & cleanup.
@@ -31,8 +31,30 @@ impl Validatable for SchemaRef {
}
pub fn load_schema(db_name: String) -> PrismaResult<SchemaRef> {
- let schema = load_schema_from_env().or(load_datamodel_file())?;
- debug!("Loaded schema:\n{}", schema);
+ let schema_json = load_schema_from_env().or_else(|_| load_datamodel_file())?;
+ Ok(serde_json::from_str::<SchemaTemplate>(&schema_json)?.build(db_name))
+}
+
+pub fn load_schema_from_env() -> PrismaResult<String> {
+ std::env::vars().for_each(|var| println!("{} -> {}", var.0, var.1));
+ debug!("Trying to load schema from env...");
+
+ utilities::get_env("PRISMA_SCHEMA_JSON").and_then(|schema| {
+ let bytes = base64::decode(&schema)?;
+ let schema_json = String::from_utf8(bytes)?;
+ debug!("Loaded schema from env.");
+
+ Ok(schema_json)
+ })
+}
+
+pub fn load_datamodel_file() -> PrismaResult<String> {
+ debug!("Trying to load schema from file...");
+ let path = utilities::get_env("PRISMA_SCHEMA_PATH")?;
+ let mut f = File::open(path)?;
+ let mut schema = String::new();
+
+ f.read_to_string(&mut schema)?;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
@@ -53,26 +75,7 @@ pub fn load_schema(db_name: String) -> PrismaResult<SchemaRef> {
let output = child.wait_with_output()?;
let inferred = String::from_utf8(output.stdout)?;
- dbg!(&inferred);
-
- Ok(serde_json::from_str::<SchemaTemplate>(&inferred)?.build(db_name))
-}
-
-pub fn load_schema_from_env() -> PrismaResult<String> {
- debug!("Trying to load schema from env...");
- utilities::get_env("PRISMA_SCHEMA").and_then(|schema| {
- let bytes = base64::decode(&schema).unwrap();
- Ok(String::from_utf8(bytes)?)
- })
-}
-
-pub fn load_datamodel_file() -> PrismaResult<String> {
- debug!("Trying to load schema from file...");
- let path = utilities::get_env("PRISMA_SCHEMA_PATH")?;
- let mut f = File::open(path)?;
- let mut schema = String::new();
-
- f.read_to_string(&mut schema)?;
- Ok(schema)
+ debug!("Loaded schema from file.");
+ Ok(inferred)
}
