Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
feat: Remove versions from orc workflows and lifecycles, making the n…
Browse files Browse the repository at this point in the history
…ame alone unique, and remove the ability to deactive lifecycles and workflows
  • Loading branch information
sungo authored and lseppala committed Apr 20, 2018
1 parent 60015f7 commit 6d26448
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 160 deletions.
12 changes: 0 additions & 12 deletions Conch/json-schema/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -950,26 +950,17 @@ definitions:
required:
- id
- name
- version
- created
- updated
- deactivated
- locked
- steps
- preflight
properties:
deactivated:
anyOf:
- type: null
- type: string
format: date-time
id:
type: string
format: uuid
name:
type: string
version:
type: number
created:
type: string
format: date-time
Expand Down Expand Up @@ -1124,7 +1115,6 @@ definitions:
required:
- id
- name
- version
- locked
- role_id
- plan
Expand All @@ -1142,8 +1132,6 @@ definitions:
updated:
type: string
format: date-time
version:
type: number
role_id:
type: string
format: uuid
Expand Down
8 changes: 2 additions & 6 deletions Conch/lib/Conch/Controller/Orc/Lifecycles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ sub create ($c) {
my $body = $c->validate_input('OrcLifecycleCreate') or return;

$body->{version} = 0 unless $body->{version};
if(Conch::Orc::Lifecycle->from_name_and_version(
$body->{name},
$body->{version}
)) {
if(Conch::Orc::Lifecycle->from_name($body->{name})) {
return $c->status_with_validation(400, Error => {
error => "Lifecycle already exists with this name and version"
error => "Lifecycle already exists with this name"
});
}


my $l = Conch::Orc::Lifecycle->new($body->%*)->save();

Expand Down
16 changes: 0 additions & 16 deletions Conch/lib/Conch/Controller/Orc/Workflows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,6 @@ sub update ($c) {
}


=head2 delete
"Delete" a workflow by marking it as deactivated
=cut

sub delete ($c) {
my $w = Conch::Orc::Workflow->from_id($c->param('id'));
return $c->status(404 => { error => "Not found" }) unless $w;
return $c->status(404 => { error => "Not found" }) if $w->deactivated;

$w->update(deactivated => Conch::Time->now)->save;
return $c->status(204);
}


=head2 create_step
Create a Workflow::Step tied to an existing Workflow
Expand Down
104 changes: 6 additions & 98 deletions Conch/lib/Conch/Orc/Lifecycle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ has 'name' => (
);


=item version
Number. Required. Defaults to 1
=cut

has 'version' => (
default => 1,
is => 'rw',
isa => Num,
required => 1,
);



=item locked
Expand Down Expand Up @@ -123,7 +109,6 @@ sub _build_serializable_attributes { [qw[
created
updated
name
version
locked
role_id
plan
Expand All @@ -150,7 +135,7 @@ sub from_id ($class, $id) {
order by wlp.plan_order
) as plan
from workflow_lifecycle l
where l.deactivated is null and l.id = ?;
where l.id = ?;
|, $id)->hash;
} catch {
Mojo::Exception->throw(__PACKAGE__."->from_id: $_");
Expand All @@ -162,13 +147,13 @@ sub from_id ($class, $id) {
}


=head2 from_name_latest
=head2 from_name
Load the latest version of a Lifecycle for a given name
Load a Lifecycle for by name
=cut

sub from_name_latest ($class, $name) {
sub from_name ($class, $name) {
my $ret;
try {
$ret = Conch::Pg->new->db->query(qq|
Expand All @@ -179,42 +164,10 @@ sub from_name_latest ($class, $name) {
order by wlp.plan_order
) as plan
from workflow_lifecycle l
where l.deactivated is null and l.name = ?
order by l.version
limit 1
where l.name = ?
|, $name)->hash;
} catch {
Mojo::Exception->throw(__PACKAGE__."->from_name_latest: $_");
return undef;
};

return undef unless $ret;
return $class->new(_fixup_timestamptzs($ret)->%*);
}

=head2 from_name_and_version
Load a Lifecycle by its name and version
=cut

sub from_name_and_version ($class, $name, $version) {
my $ret;
try {
$ret = Conch::Pg->new->db->query(qq|
select l.*, array(
select wlp.workflow_id
from workflow_lifecycle_plan wlp
where wlp.lifecycle_id = l.id
order by wlp.plan_order
) as plan
from workflow_lifecycle l
where l.deactivated is null
and l.name = ?
and l.version = ?;
|, $name, $version)->hash;
} catch {
Mojo::Exception->throw(__PACKAGE__."->from_name_and_version: $_");
Mojo::Exception->throw(__PACKAGE__."->from_name: $_");
return undef;
};

Expand All @@ -223,41 +176,6 @@ sub from_name_and_version ($class, $name, $version) {
}


=head2 many_from_name
Load all Lifecycles that match a given name
=cut

sub many_from_name ($class, $name) {
my $ret;
try {
$ret = Conch::Pg->new->db->query(qq|
select l.*, array(
select wlp.workflow_id
from workflow_lifecycle_plan wlp
where wlp.lifecycle_id = l.id
order by wlp.plan_order
) as plan
from workflow_lifecycle l
where l.deactivated is null and l.name = ?;
|, $name)->hashes;
} catch {
Mojo::Exception->throw(__PACKAGE__."->many_from_name: $_");
return undef;
};

return [] unless $ret and $ret->@*;

my @many = map {
$class->new(_fixup_timestamptzs($_)->%*);
} $ret->@*;

return \@many;
}



=head2 all
Returns an arrayref containing all active Lifecycles
Expand All @@ -275,7 +193,6 @@ sub all ($class) {
order by wlp.plan_order
) as plan
from workflow_lifecycle l
where l.deactivated is null;
|)->hashes;
} catch {
Mojo::Exception->throw(__PACKAGE__."->all: $_");
Expand Down Expand Up @@ -307,10 +224,6 @@ sub save ($self) {
delete @fields{ qw(id plan created updated) };
$fields{updated} = 'NOW()';

if ($fields{deactivated}) {
$fields{deactivated} = $fields{deactivated}->timestamptz;
}

my $ret;
try {
if($self->id) {
Expand All @@ -337,11 +250,6 @@ sub save ($self) {
$self->_set_id($ret->{id});
$self->_set_created(Conch::Time->new($ret->{created}));
$self->_set_updated(Conch::Time->new($ret->{updated}));

if($ret->{deactivated}) {
$self->deactivated($ret->{deactivated});
}

return $self;
}

Expand Down
54 changes: 32 additions & 22 deletions Conch/lib/Conch/Orc/Workflow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ has 'name' => (
);


=item version
Number. Required. Defaults to 1
=cut

has 'version' => (
default => 1,
is => 'rw',
isa => Num,
required => 1,
);


=item locked
Boolean. Defaults to 0
Expand Down Expand Up @@ -126,10 +112,8 @@ has 'steps' => (
sub _build_serializable_attributes {[qw[
id
name
version
created
updated
deactivated
locked
preflight
steps
Expand Down Expand Up @@ -196,6 +180,36 @@ sub from_id ($class, $id) {
return $class->new(_fixup_timestamptzs($ret)->%*);
}

=head2 from_name
Load a Workflow by its name
=cut

sub from_name ($class, $id) {
my $ret;
try {
$ret = Conch::Pg->new->db->query(qq|
select w.*, array(
select ws.id
from workflow_step ws
where ws.workflow_id = w.id
order by ws.step_order
) as steps
from workflow w
where w.name = ?;
|, $id)->hash;
} catch {
Mojo::Exception->throw(__PACKAGE__."->from_name: $_");
return undef;
};

return undef unless $ret;

return $class->new(_fixup_timestamptzs($ret)->%*);
}



=head2 all
Expand All @@ -213,8 +227,7 @@ sub all ($class) {
where ws.workflow_id = w.id
order by ws.step_order
) as steps
from workflow w
where deactivated is null;
from workflow w;
|)->hashes;
} catch {
Mojo::Exception->throw(__PACKAGE__."->all: $_");
Expand Down Expand Up @@ -243,13 +256,10 @@ Returns C<$self>, allowing for method chaining
sub save ($self) {
my $db = Conch::Pg->new()->db;

$self->_set_updated(Conch::Time->now);
my %fields = (
deactivated => $self->deactivated ? $self->deactivated->timestamptz : undef,
locked => $self->locked,
name => $self->name,
updated => $self->updated->timestamptz,
version => $self->version,
updated => 'NOW()',
preflight => $self->preflight,
);

Expand Down
1 change: 0 additions & 1 deletion Conch/lib/Conch/Route/Orc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ sub load ( $class, $r ) {

my $wi = $w->under("/:id");
$wi->post("/")->to("Orc::Workflows#update");
$wi->get("/delete")->to("Orc::Workflows#delete");
$wi->post("/step")->to("Orc::Workflows#create_step");

my $si = $o->under("/step/:id");
Expand Down
5 changes: 0 additions & 5 deletions Conch/t/integration/orc/build.t
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ $t->post_ok(BASE."/workflow", json => {

$t->get_ok($t->tx->res->headers->location)->json_is(
'/locked' => 0,
)->json_is(
'/version' => 1,
)->json_schema_is("Workflow");

my $wid = $t->tx->res->json->{id};
Expand All @@ -117,9 +115,6 @@ $t->get_ok(BASE."/workflow/".$wid)->status_is(200)->json_is(
'/name' => 'sungo'
)->json_schema_is('Workflow');

$t->get_ok(BASE."/workflow/".$wid."/delete")->status_is(204);

$t->get_ok(BASE."/workflow/".$wid)->status_is(404)->json_schema_is("Error");

##########################

Expand Down
14 changes: 14 additions & 0 deletions sql/migrations/0027-orc-simplification.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT run_migration(27, $$

drop index workflow_name_idx;
alter table workflow drop constraint workflow_name_version_key;
alter table workflow add unique (name);

alter table workflow drop column version;
alter table workflow drop column deactivated;

drop index workflow_lifecycle_name_version_idx;
alter table workflow_lifecycle add unique(name);
alter table workflow_lifecycle drop column deactivated;

$$);

0 comments on commit 6d26448

Please sign in to comment.