Skip to content

Commit 9c17d3b

Browse files
committed
Merge branch 'master' into extension_structure_docs
2 parents 790792e + 7f8dc66 commit 9c17d3b

File tree

10 files changed

+144
-54
lines changed

10 files changed

+144
-54
lines changed

cli/Cargo.lock

Lines changed: 41 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ anyhow = "1.0.69"
1111
clap = { version = "4.1.6", features = ["derive"] }
1212
dirs = "5.0.1"
1313
postgrest = "1.5.0"
14+
regex = "1.9"
1415
reqwest = { version = "0.11.14", features = ["json", "native-tls-vendored"] }
1516
rpassword = "7.2.0"
1617
serde = { version = "1.0.156", features = ["derive"] }

cli/src/commands/publish.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub async fn publish(
2424
let request = create_publish_package_request(&payload);
2525
client.publish_package(&jwt, &request).await?;
2626

27+
if payload.install_files.is_empty() {
28+
return Err(anyhow::anyhow!("No valid script file (.sql) found."));
29+
}
30+
2731
let mut num_published = 0;
2832

2933
for install_file in &payload.install_files {

cli/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl Default for Config {
6262
registries.insert(
6363
registry_name.to_string(),
6464
Registry {
65-
base_url: url::Url::parse("https://database.dev")
66-
.expect("Failed to parse database.dev url"),
65+
base_url: url::Url::parse("https://api.database.dev")
66+
.expect("Failed to parse api.database.dev url"),
6767
api_key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyYndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzIsImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJrzM0AQKsu_5k134s".to_string(),
6868
},
6969
);

cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async fn main() -> anyhow::Result<()> {
126126
// confirm that a registry with the given name exists
127127
config.get_registry(registry_name)?;
128128
commands::login::login(registry_name)?;
129+
println!("Login successful");
129130
Ok(())
130131
}
131132
}

cli/src/models.rs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Payload {
146146

147147
if !util::is_valid_extension_name(&extension_name) {
148148
return Err(anyhow::anyhow!(
149-
"invalid extension name detected {}",
149+
"Invalid extension name detected: {}. It must begin with an alphabet, contain only alphanumeric characters or `_` and should be between 2 and 32 characters long.",
150150
extension_name
151151
));
152152
}
@@ -166,31 +166,46 @@ impl Payload {
166166
match &parts[..] {
167167
[file_ext_name, ver] => {
168168
// Make sure the file's extension name matches the control file
169-
if file_ext_name == &extension_name && util::is_valid_version(ver) {
170-
let ifile = InstallFile {
171-
filename: file_name.to_string(),
172-
version: ver.to_string(),
173-
body: fs::read_to_string(&path)
174-
.context(format!("Failed to read file {}", &file_name))?,
175-
};
176-
install_files.push(ifile);
169+
if file_ext_name != &extension_name {
170+
println!("Warning: file `{file_name}` will be skipped because its extension name(`{file_ext_name}`) doesn't match `{extension_name}`");
171+
continue;
172+
}
173+
if !util::is_valid_version(ver) {
174+
println!("Warning: file `{file_name}` will be skipped because its version (`{ver}`) is invalid. It should be have the format `major.minor.patch`.");
175+
continue;
177176
}
177+
178+
let ifile = InstallFile {
179+
filename: file_name.to_string(),
180+
version: ver.to_string(),
181+
body: fs::read_to_string(&path)
182+
.context(format!("Failed to read file {}", &file_name))?,
183+
};
184+
install_files.push(ifile);
178185
}
179186
[file_ext_name, from_ver, to_ver] => {
180187
// Make sure the file's extension name matches the control file
181-
if file_ext_name == &extension_name
182-
&& util::is_valid_version(from_ver)
183-
&& util::is_valid_version(to_ver)
184-
{
185-
let ufile = UpgradeFile {
186-
filename: file_name.to_string(),
187-
from_version: from_ver.to_string(),
188-
to_version: to_ver.to_string(),
189-
body: fs::read_to_string(&path)
190-
.context(format!("Failed to read file {}", &file_name))?,
191-
};
192-
upgrade_files.push(ufile);
188+
if file_ext_name != &extension_name {
189+
println!("Warning: file `{file_name}` will be skipped because its extension name(`{file_ext_name}`) doesn't match `{extension_name}`");
190+
continue;
193191
}
192+
if !util::is_valid_version(from_ver) {
193+
println!("Warning: file `{file_name}` will be skipped because its from version(`{from_ver}`) is invalid. It should be have the format `major.minor.patch`.");
194+
continue;
195+
}
196+
if !util::is_valid_version(to_ver) {
197+
println!("Warning: file `{file_name}` will be skipped because its from version(`{to_ver}`) is invalid. It should be have the format `major.minor.patch`.");
198+
continue;
199+
}
200+
201+
let ufile = UpgradeFile {
202+
filename: file_name.to_string(),
203+
from_version: from_ver.to_string(),
204+
to_version: to_ver.to_string(),
205+
body: fs::read_to_string(&path)
206+
.context(format!("Failed to read file {}", &file_name))?,
207+
};
208+
upgrade_files.push(ufile);
194209
}
195210
_ => (),
196211
}
@@ -264,7 +279,9 @@ impl ControlFileRef {
264279
return self.read_control_line_value(line);
265280
}
266281
}
267-
Err(anyhow::anyhow!("default version is required"))
282+
Err(anyhow::anyhow!(
283+
"`default_version` in control file is required"
284+
))
268285
}
269286

270287
fn read_control_line_value(&self, line: &str) -> anyhow::Result<String> {

cli/src/util.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Context;
2+
use regex::Regex;
23
use sqlx::postgres::PgConnection;
34
use sqlx::Connection;
45
use std::fs::{File, OpenOptions};
@@ -10,11 +11,28 @@ pub async fn get_connection(connection_str: &str) -> anyhow::Result<PgConnection
1011
.context("Failed to establish PostgreSQL connection")
1112
}
1213

13-
pub fn is_valid_extension_name(_name: &str) -> bool {
14-
true
14+
pub fn is_valid_extension_name(name: &str) -> bool {
15+
let name_regex = Regex::new(r"^[A-z][A-z0-9\_]{2,32}$").expect("regex is valid");
16+
name_regex.is_match(name)
1517
}
1618

17-
pub fn is_valid_version(_version: &str) -> bool {
19+
pub fn is_valid_version(version: &str) -> bool {
20+
let nums: Vec<&str> = version.split('.').collect();
21+
if nums.len() != 3 {
22+
println!("1");
23+
return false;
24+
}
25+
26+
for num_str in nums {
27+
let num: i16 = match num_str.parse() {
28+
Ok(n) => n,
29+
_ => return false,
30+
};
31+
if num < 0 {
32+
return false;
33+
}
34+
}
35+
1836
true
1937
}
2038

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
## Overview
2020

21-
dbdev is a package manager for Postgres [trusted lanuguage extensions](https://github.com/aws/pg_tle) (TLEs). It consists of:
21+
dbdev is a package manager for Postgres [trusted language extensions](https://github.com/aws/pg_tle) (TLEs). It consists of:
2222

2323
- [database.dev](https://database.dev): our first-party package registry to store and distribute TLEs.
2424
- dbdev CLI: a CLI for publishing TLEs to a registry.

website/package-lock.json

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
"tailwind-merge": "^1.10.0",
4242
"tailwindcss-animate": "^1.0.5",
4343
"typescript": "4.9.5",
44-
"zod": "^3.21.4"
44+
"zod": "^3.22.3"
4545
},
4646
"devDependencies": {
4747
"@tailwindcss/forms": "^0.5.3",
4848
"@tailwindcss/typography": "^0.5.9",
4949
"autoprefixer": "^10.4.13",
50-
"postcss": "^8.4.21",
50+
"postcss": "^8.4.31",
5151
"prettier": "^3.0.2",
5252
"tailwindcss": "^3.2.6"
5353
}

0 commit comments

Comments
 (0)