generated from alecodes/base-template
fix: create parent folders when creating schema file
This commit is contained in:
parent
b93f037017
commit
6ac6c2c178
4 changed files with 122 additions and 24 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
set dotenv-load := true
|
set dotenv-load := true
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
# cargo run --bin cli -- query "SELECT * FROM sources;"
|
cargo run --bin cli -- query "SELECT * FROM sources;"
|
||||||
cargo run --bin cli -- discover
|
|
||||||
|
build-schema:
|
||||||
|
cargo run --bin cli -- discover -o examples/schema.toml
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
[public]
|
|
||||||
|
|
||||||
[public.entries]
|
|
||||||
|
|
||||||
name = "entries"
|
|
||||||
display_name = "entries"
|
|
||||||
columns = [
|
|
||||||
{ name = "id", col_type = "Integer", default = false, not_null = true, reference = { table = "", identity = "", label = "" } },
|
|
||||||
]
|
|
||||||
|
|
||||||
[public.sources]
|
|
||||||
|
|
||||||
name = "sources"
|
|
||||||
display_name = "Sources"
|
|
||||||
|
|
||||||
[[public.sources.columns]]
|
|
||||||
name = "id"
|
|
||||||
col_type = "Integer"
|
|
||||||
default = false
|
|
||||||
not_null = true
|
|
||||||
reference = { table = "", identity = "", label = "" }
|
|
||||||
110
examples/schema.toml
Normal file
110
examples/schema.toml
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
[public.entry_categories]
|
||||||
|
display_name = "Entry Categories"
|
||||||
|
|
||||||
|
[[public.entry_categories.columns]]
|
||||||
|
name = "entry_id"
|
||||||
|
type = "Integer"
|
||||||
|
not_null = true
|
||||||
|
reference = { table = "entries", identity = "id", label = "Entry Id" }
|
||||||
|
|
||||||
|
[[public.entry_categories.columns]]
|
||||||
|
name = "entry_date"
|
||||||
|
type = "Date"
|
||||||
|
not_null = true
|
||||||
|
reference = { table = "entries", identity = "id", label = "Entry Id" }
|
||||||
|
|
||||||
|
[[public.entry_categories.columns]]
|
||||||
|
name = "category_id"
|
||||||
|
type = "Integer"
|
||||||
|
not_null = true
|
||||||
|
reference = { table = "categories", identity = "id", label = "Category Id" }
|
||||||
|
|
||||||
|
[public.sources]
|
||||||
|
display_name = "Sources"
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "id"
|
||||||
|
type = "Integer"
|
||||||
|
default = "nextval('sources_id_seq'::regclass)"
|
||||||
|
not_null = true
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "name"
|
||||||
|
not_null = true
|
||||||
|
type = { Varchar = { length = 20 } }
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "uid"
|
||||||
|
not_null = true
|
||||||
|
type = { Varchar = { length = 8 } }
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "uri"
|
||||||
|
not_null = true
|
||||||
|
type = { Varchar = {} }
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "created_at"
|
||||||
|
default = "CURRENT_TIMESTAMP"
|
||||||
|
not_null = true
|
||||||
|
type = { TimestampWithTimeZone = { precision = 6 } }
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "updated_at"
|
||||||
|
not_null = false
|
||||||
|
type = { TimestampWithTimeZone = { precision = 6 } }
|
||||||
|
|
||||||
|
[[public.sources.columns]]
|
||||||
|
name = "deleted_at"
|
||||||
|
not_null = false
|
||||||
|
type = { TimestampWithTimeZone = { precision = 6 } }
|
||||||
|
|
||||||
|
[public.categories]
|
||||||
|
display_name = "Categories"
|
||||||
|
|
||||||
|
[[public.categories.columns]]
|
||||||
|
name = "id"
|
||||||
|
type = "Integer"
|
||||||
|
default = "nextval('category_id_seq'::regclass)"
|
||||||
|
not_null = true
|
||||||
|
|
||||||
|
[[public.categories.columns]]
|
||||||
|
name = "name"
|
||||||
|
not_null = true
|
||||||
|
type = { Varchar = { length = 20 } }
|
||||||
|
|
||||||
|
[[public.categories.columns]]
|
||||||
|
name = "uid"
|
||||||
|
not_null = false
|
||||||
|
type = { Varchar = { length = 8 } }
|
||||||
|
|
||||||
|
[public.entries]
|
||||||
|
display_name = "Entries"
|
||||||
|
|
||||||
|
[[public.entries.columns]]
|
||||||
|
name = "id"
|
||||||
|
type = "Integer"
|
||||||
|
default = "nextval('entries_id_seq'::regclass)"
|
||||||
|
not_null = true
|
||||||
|
|
||||||
|
[[public.entries.columns]]
|
||||||
|
name = "date"
|
||||||
|
type = "Date"
|
||||||
|
default = "CURRENT_TIMESTAMP"
|
||||||
|
not_null = true
|
||||||
|
|
||||||
|
[[public.entries.columns]]
|
||||||
|
name = "source_id"
|
||||||
|
type = "Integer"
|
||||||
|
not_null = true
|
||||||
|
reference = { table = "sources", identity = "id", label = "Source Id" }
|
||||||
|
|
||||||
|
[[public.entries.columns]]
|
||||||
|
name = "uid"
|
||||||
|
not_null = true
|
||||||
|
type = { Varchar = {} }
|
||||||
|
|
||||||
|
[[public.entries.columns]]
|
||||||
|
name = "text"
|
||||||
|
type = "Text"
|
||||||
|
not_null = false
|
||||||
|
|
@ -76,7 +76,14 @@ pub async fn discover_scheme(
|
||||||
.insert(schema.schema.to_owned(), Schema::from(schema));
|
.insert(schema.schema.to_owned(), Schema::from(schema));
|
||||||
|
|
||||||
let mut buffer: Box<dyn io::Write> = match output {
|
let mut buffer: Box<dyn io::Write> = match output {
|
||||||
Some(path) => Box::new(File::create(Path::new(&path))?),
|
Some(path) => {
|
||||||
|
let path = Path::new(&path);
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
std::fs::create_dir_all(parent)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box::new(File::create(path)?)
|
||||||
|
}
|
||||||
None => Box::new(io::stdout()),
|
None => Box::new(io::stdout()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue