Skip to content

Commit cf5c919

Browse files
committed
fix(cli): dir => root typegraph, migration paths => relative to dir
1 parent a3ce96c commit cf5c919

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

meta-cli/src/com/server.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use serde_json::json;
1313
use std::{
1414
io::{Error, ErrorKind},
1515
net::{Ipv4Addr, SocketAddrV4, TcpListener},
16+
path::PathBuf,
1617
sync::Arc,
1718
};
1819

@@ -40,20 +41,20 @@ pub fn get_instance_port() -> u16 {
4041
#[derive(Debug, Deserialize)]
4142
struct QueryConfigParams {
4243
typegraph: String,
44+
typegraph_path: PathBuf,
4345
}
4446

4547
#[get("/config")]
4648
async fn config(req: HttpRequest) -> impl Responder {
47-
let parsed = Query::<QueryConfigParams>::from_query(req.query_string());
48-
let folder = match parsed {
49-
Ok(p) => p.typegraph.to_owned(),
50-
Err(_) => "".to_string(),
51-
};
49+
let mut parsed = Query::<QueryConfigParams>::from_query(req.query_string()).unwrap();
50+
51+
parsed.typegraph_path.pop(); // pop file.ext
52+
let artefact_base_dir = parsed.typegraph_path.clone();
53+
5254
let endpoint = ServerStore::get_endpoint();
5355
let secrets = ServerStore::get_secrets();
5456
let migration_action = ServerStore::get_migration_action();
5557
let prefix = ServerStore::get_prefix();
56-
5758
match ServerStore::get_config() {
5859
Some(config) => {
5960
let data = json!({
@@ -64,9 +65,9 @@ async fn config(req: HttpRequest) -> impl Responder {
6465
"secrets": secrets,
6566
"prefix": prefix,
6667
"artifactsConfig": json!({
67-
"dir": config.base_dir.display().to_string(),
68+
"dir": artefact_base_dir,
6869
"prismaMigration": {
69-
"migrationDir": config.prisma_migrations_dir(&folder),
70+
"migrationDir": config.prisma_migrations_dir_rel(&parsed.typegraph),
7071
"action": serde_json::to_value(migration_action).unwrap()
7172
},
7273
}),

meta-cli/src/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ impl Config {
244244
.unwrap_or(&DEFAULT_LOADER_CONFIG)
245245
}
246246

247-
pub fn prisma_migrations_dir(&self, typegraph: &str) -> PathBuf {
248-
let mut path = self.base_dir.join(
249-
self.typegraphs
250-
.materializers
251-
.prisma
252-
.migrations_path
253-
.as_deref()
254-
.unwrap_or_else(|| Path::new("prisma/migrations")),
255-
);
247+
pub fn prisma_migrations_dir_rel(&self, typegraph: &str) -> PathBuf {
248+
let mut path = self
249+
.typegraphs
250+
.materializers
251+
.prisma
252+
.migrations_path
253+
.as_deref()
254+
.unwrap_or_else(|| Path::new("prisma/migrations"))
255+
.to_path_buf();
256256
path.push(typegraph);
257257
path
258258
}

meta-cli/src/deploy/push/pusher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl PushResult {
129129

130130
let migdir = ServerStore::get_config()
131131
.unwrap()
132-
.prisma_migrations_dir(&self.original_name);
132+
.prisma_migrations_dir_rel(&self.original_name);
133133

134134
for migrations in self.migrations.iter() {
135135
let dest = migdir.join(&migrations.runtime);

typegraph/node/sdk/src/tg_manage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export class Manager {
100100
async #requestConfig(): Promise<CLISuccess<CLIConfigRequest>> {
101101
const params = new URLSearchParams({
102102
typegraph: this.#typegraph.name,
103+
typegraph_path: this.#typegraphPath,
103104
});
104105
const response = await fetch(new URL("config?" + params, this.#endpoint));
105106
return (await response.json()) as CLISuccess<CLIConfigRequest>;

typegraph/python/typegraph/graph/tg_manage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515
from typegraph.graph.tg_deploy import TypegraphDeployParams, tg_deploy
16-
from urllib import request
16+
from urllib import request, parse
1717

1818
from typegraph.graph.shared_types import BasicAuth, TypegraphOutput
1919

@@ -125,7 +125,10 @@ def request_command(self) -> CLIServerResponse:
125125

126126
def request_config(self) -> CLIConfigRequest:
127127
tg_name = self.typegraph.name
128-
req = request.Request(f"{self.endpoint}/config?typegraph={tg_name}")
128+
tg_path = parse.quote(self.typegraph_path)
129+
req = request.Request(
130+
f"{self.endpoint}/config?typegraph={tg_name}&typegraph_path={tg_path}"
131+
)
129132
raw = request.urlopen(req).read().decode()
130133
cli_res = json.loads(raw)["data"]
131134

0 commit comments

Comments
 (0)