Skip to content

Commit

Permalink
allow publishing relocatable and requires package columns
Browse files Browse the repository at this point in the history
  • Loading branch information
imor committed Nov 10, 2023
1 parent aee31ea commit ca4e31a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub enum TokenType {
pub struct PublishPackageRequest<'a> {
pub package_name: &'a str,
pub package_description: &'a Option<String>,
pub relocatable: bool,
pub requires: &'a [String],
}

#[derive(Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ fn create_publish_package_request(payload: &Payload) -> PublishPackageRequest {
PublishPackageRequest {
package_name: &payload.metadata.extension_name,
package_description: &payload.metadata.comment,
relocatable: payload.metadata.relocatable,
requires: &payload.metadata.requires,
}
}

Expand Down
20 changes: 16 additions & 4 deletions cli/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub struct Metadata {
pub extension_name: String,
pub default_version: String,
pub comment: Option<String>,
pub requires: Option<Vec<String>>,
pub relocatable: bool,
pub requires: Vec<String>,
}

impl Metadata {
Expand All @@ -23,6 +24,7 @@ impl Metadata {
extension_name: control_file_ref.extension_name()?.clone(),
default_version: control_file_ref.default_version()?.clone(),
comment: control_file_ref.comment()?.clone(),
relocatable: control_file_ref.relocatable()?,
requires: control_file_ref.requires()?.clone(),
})
}
Expand Down Expand Up @@ -261,16 +263,26 @@ impl ControlFileRef {

// A list of names of extensions that this extension depends on, for example requires = 'foo,
// bar'. Those extensions must be installed before this one can be installed.
fn requires(&self) -> anyhow::Result<Option<Vec<String>>> {
fn requires(&self) -> anyhow::Result<Vec<String>> {
for line in self.contents.lines() {
if line.starts_with("requires") {
let value = self.read_control_line_value(line)?;
let required_packages: Vec<String> =
value.split(',').map(|x| x.trim().to_string()).collect();
return Ok(Some(required_packages));
return Ok(required_packages);
}
}
Ok(None)
Ok(vec![])
}

fn relocatable(&self) -> anyhow::Result<bool> {
for line in self.contents.lines() {
if line.starts_with("relocatable") {
let value: bool = self.read_control_line_value(line)?.parse()?;
return Ok(value);
}
}
Ok(false)
}

fn default_version(&self) -> anyhow::Result<String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
grant insert (partial_name, handle, control_description, control_relocatable, control_requires)
on app.packages
to authenticated;

grant update (control_description, control_relocatable, control_requires)
on app.packages
to authenticated;

create or replace function public.publish_package(
package_name app.valid_name,
package_description varchar(1000),
relocatable bool default false,
requires text[] default '{}'
)
returns void
language plpgsql
as $$
declare
account app.accounts = account from app.accounts account where id = auth.uid();
begin
if account.handle is null then
raise exception 'user not logged in';
end if;

insert into app.packages(handle, partial_name, control_description, control_relocatable, control_requires)
values (account.handle, package_name, package_description, relocatable, requires)
on conflict on constraint packages_handle_partial_name_key
do update
set control_description = excluded.control_description,
control_relocatable = excluded.control_relocatable,
control_requires = excluded.control_requires;
end;
$$;

0 comments on commit ca4e31a

Please sign in to comment.