Skip to content

Commit 41a6678

Browse files
committed
fix(sdk/python): migration not considered
1 parent 542d976 commit 41a6678

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

meta-cli/src/com/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ async fn config(req: HttpRequest) -> impl Responder {
7070
"secrets": secrets,
7171
"prefix": prefix,
7272
"artifactsConfig": {
73+
// on sdk's side, cwd will match to the parent process (cli)
74+
// thus `dir` must be explicitly set to the canonical typegraph's `workdir`
7375
"dir": artefact_base_dir,
7476
"prismaMigration": {
77+
// only the cli is aware of the convention migrationDir := tg_workdir + config_folder + tg_name
7578
"migrationDir": config.prisma_migrations_dir_rel(&parsed.typegraph),
7679
"action": serde_json::to_value(migration_action).unwrap()
7780
},

meta-cli/src/config.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
use anyhow::{anyhow, Context, Result};
4+
use anyhow::{anyhow, bail, Context, Result};
55
use globset::{Glob, GlobSet, GlobSetBuilder};
66
use lazy_static::lazy_static;
77
use reqwest::Url;
@@ -244,18 +244,29 @@ impl Config {
244244
.unwrap_or(&DEFAULT_LOADER_CONFIG)
245245
}
246246

247-
pub fn prisma_migrations_dir_rel(&self, typegraph: &str) -> PathBuf {
247+
/// `config migration dir` + `runtime` + `tg_name`
248+
pub fn prisma_migrations_dir_rel(&self, tg_name: &str) -> PathBuf {
248249
let mut path = self
249250
.typegraphs
250251
.materializers
251252
.prisma
252253
.migrations_path
253254
.as_deref()
254-
.unwrap_or_else(|| Path::new("prisma/migrations"))
255+
.unwrap_or_else(|| Path::new("prisma-migrations"))
255256
.to_path_buf();
256-
path.push(typegraph);
257+
path.push(tg_name);
257258
path
258259
}
260+
261+
/// canonical path to the migration given the typegraph path
262+
pub fn prisma_migration_dir_abs(&self, tg_path: &Path, tg_name: &str) -> Result<PathBuf> {
263+
if tg_path.is_dir() {
264+
bail!("Given typegraph path {} is not a file", tg_path.display());
265+
}
266+
let mut base = tg_path.to_path_buf().clone();
267+
base.pop(); // remove file
268+
Ok(base.join(self.prisma_migrations_dir_rel(tg_name)))
269+
}
259270
}
260271

261272
#[cfg(test)]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ impl PushResult {
135135
name = name.cyan()
136136
));
137137

138+
// tg workdir + prisma_migration_rel
138139
let migdir = ServerStore::get_config()
139140
.unwrap()
140-
.prisma_migrations_dir_rel(&self.original_name);
141+
.prisma_migration_dir_abs(&self.sdk_response.typegraph_path, &self.original_name)?;
141142

142143
// TODO: use unpack from sdk? This requires another load event though.
143144
for migrations in self.migrations.iter() {

typegraph/core/src/utils/postprocess/prisma_rt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use common::typegraph::Typegraph;
99
use crate::utils::fs_host;
1010
use crate::utils::postprocess::PostProcessor;
1111
use crate::wit::core::MigrationConfig;
12-
use crate::wit::metatype::typegraph::host::{eprint, file_exists};
12+
use crate::wit::metatype::typegraph::host::{eprint, path_exists};
1313

1414
pub struct PrismaProcessor {
1515
config: MigrationConfig,
@@ -41,12 +41,16 @@ impl PrismaProcessor {
4141
rt_data.migration_options = Some(MigrationOptions {
4242
migration_files: {
4343
let path = fs_host::make_absolute(&path)?;
44-
match file_exists(&path.display().to_string())? {
44+
match path_exists(&path.display().to_string())? {
4545
true => {
46+
eprint("PACKING IT..");
4647
let base64 = fs_host::compress_and_encode_base64(path)?;
4748
Some(base64)
4849
}
49-
false => None,
50+
false => {
51+
eprint(&format!("FOUND NOTHING AT {}", path.display()));
52+
None
53+
}
5054
}
5155
},
5256
create: self.config.action.create,

typegraph/core/wit/typegraph.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ interface host {
553553
print: func(s: string)
554554
eprint: func(s: string)
555555
expand-glob: func(root: string, exclude: list<string>) -> result<list<string>, string>
556-
file-exists: func(path: string) -> result<bool, string>
556+
path-exists: func(path: string) -> result<bool, string>
557557
read-file: func(path: string) -> result<list<u8>, string>
558558
write-file: func(path: string, data: list<u8>) -> result<_, string>
559559
get-cwd: func() -> result<string, string>

typegraph/node/sdk/src/host/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function getCwd(): string {
5656
}
5757
}
5858

59-
export function fileExists(filePath: string): boolean {
59+
export function pathExists(filePath: string): boolean {
6060
try {
6161
return fs.existsSync(filePath);
6262
} catch (err) {

typegraph/python/typegraph/host/host.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def expand_glob(self, root: str, exclude: List[str]) -> Result[List[str], str]:
3636
except Exception as e:
3737
return Err(str(e))
3838

39-
def file_exists(self, path: str) -> Result[bool, str]:
39+
def path_exists(self, path: str) -> Result[bool, str]:
4040
try:
41-
return Ok(os.path.isfile(path))
41+
return Ok(os.path.isfile(path) or os.path.isdir(path))
4242
except Exception as e:
4343
return Err(str(e))
4444

0 commit comments

Comments
 (0)