Permalink
Browse files

Added repository props, including a schema version.

  • Loading branch information...
1 parent dcd9cc5 commit d4e1575e9d10147435f333c49dcd66cdc1286687 Jeffrey Ryan Thalhammer committed May 9, 2012
Showing with 212 additions and 5 deletions.
  1. +13 −0 lib/Pinto/Database.pm
  2. +66 −0 lib/Pinto/Repository.pm
  3. +14 −3 lib/Pinto/Schema.pm
  4. +103 −0 lib/Pinto/Schema/Result/RepositoryProperty.pm
  5. +10 −2 sql/pinto.sql
  6. +6 −0 t/09-init.t
View
@@ -138,13 +138,26 @@ sub create_stack {
#-------------------------------------------------------------------------------
+sub repository_properties {
+ my ($self) = @_;
+
+ return $self->schema->resultset('RepositoryProperty');
+}
+
+#-------------------------------------------------------------------------------
+
sub deploy {
my ($self) = @_;
$self->mkpath( $self->config->db_dir() );
$self->debug( 'Creating database at ' . $self->config->db_file );
$self->schema->deploy;
+ my $props = { name => 'pinto:schema-version',
+ value => $self->schema->version };
+
+ $self->schema->resultset('RepositoryProperty')->create($props);
+
return $self;
}
@@ -4,6 +4,7 @@ package Pinto::Repository;
use Moose;
+use Pinto::Util;
use Pinto::Store;
use Pinto::Locker;
use Pinto::Database;
@@ -125,6 +126,71 @@ sub BUILD {
#-------------------------------------------------------------------------------
+sub get_property {
+ my ($self, @prop_names) = @_;
+
+ my %props = %{ $self->get_properties };
+ return @props{@prop_names};
+}
+
+#-------------------------------------------------------------------------------
+
+sub get_properties {
+ my ($self) = @_;
+
+ my @props = $self->db->repository_properties->search->all;
+
+ return { map { $_->name => $_->value } @props };
+}
+
+#-------------------------------------------------------------------------------
+
+sub set_property {
+ my ($self, $prop_name, $value) = @_;
+ return $self->set_properties( {$prop_name => $value} );
+}
+
+#-------------------------------------------------------------------------------
+
+sub set_properties {
+ my ($self, $props) = @_;
+
+ while (my ($name, $value) = each %{$props}) {
+ $name = Pinto::Util::normalize_property_name($name);
+ my $nv_pair = {name => $name, value => $value};
+ $self->db->repository_properties->update_or_create($nv_pair);
+ }
+
+ return $self;
+}
+
+#-------------------------------------------------------------------------------
+
+sub delete_property {
+ my ($self, @prop_names) = @_;
+
+ for my $prop_name (@prop_names) {
+ my $where = {name => $prop_name};
+ my $prop = $self->db->repository_properties->update_or_create($where);
+ $prop->delete if $prop;
+ }
+
+ return $self;
+}
+
+#-------------------------------------------------------------------------------
+
+sub delete_properties {
+ my ($self) = @_;
+
+ my $props_rs = $self->db->repository_properties->search;
+ $props_rs->delete;
+
+ return $self;
+}
+
+#-------------------------------------------------------------------------------
+
=method get_stack()
=method get_stack( name => $stack_name )
View
@@ -23,10 +23,21 @@ __PACKAGE__->load_namespaces;
#-------------------------------------------------------------------------------
+use MooseX::ClassAttribute;
+
+#-------------------------------------------------------------------------------
+
has logger => (
- is => 'rw',
- isa => 'Pinto::Logger',
- handles => [ qw(debug notice info warning error fatal) ],
+ is => 'rw',
+ isa => 'Pinto::Logger',
+ handles => [ qw(debug notice info warning error fatal) ],
+);
+
+
+class_has version => (
+ is => 'ro',
+ isa => 'Int',
+ default => 1,
);
#-------------------------------------------------------------------------------
@@ -0,0 +1,103 @@
+use utf8;
+package Pinto::Schema::Result::RepositoryProperty;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Pinto::Schema::Result::RepositoryProperty
+
+=cut
+
+use strict;
+use warnings;
+
+use Moose;
+use MooseX::NonMoose;
+use MooseX::MarkAsMethods autoclean => 1;
+extends 'DBIx::Class::Core';
+
+=head1 TABLE: C<repository_property>
+
+=cut
+
+__PACKAGE__->table("repository_property");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'integer'
+ is_auto_increment: 1
+ is_nullable: 0
+
+=head2 name
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 value
+
+ data_type: 'text'
+ default_value: (empty string)
+ is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
+ "name",
+ { data_type => "text", is_nullable => 0 },
+ "value",
+ { data_type => "text", default_value => "", is_nullable => 1 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<name_unique>
+
+=over 4
+
+=item * L</name>
+
+=back
+
+=cut
+
+__PACKAGE__->add_unique_constraint("name_unique", ["name"]);
+
+=head1 L<Moose> ROLES APPLIED
+
+=over 4
+
+=item * L<Pinto::Role::Schema::Result>
+
+=back
+
+=cut
+
+
+with 'Pinto::Role::Schema::Result';
+
+
+# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-05-08 21:12:59
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JEYmGo1sVZSGRVeWvVpv0g
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+__PACKAGE__->meta->make_immutable;
+1;
View
@@ -1,4 +1,11 @@
+CREATE TABLE repository_property (
+ id INTEGER PRIMARY KEY NOT NULL,
+ name TEXT NOT NULL,
+ value TEXT DEFAULT ''
+);
+
+
CREATE TABLE distribution (
id INTEGER PRIMARY KEY NOT NULL,
path TEXT NOT NULL,
@@ -68,5 +75,6 @@ CREATE UNIQUE INDEX c ON stack(name);
CREATE UNIQUE INDEX d ON registration(stack, package_name);
CREATE UNIQUE INDEX e ON prerequisite(distribution, package_name);
CREATE UNIQUE INDEX f ON stack_property(stack, name);
-CREATE INDEX g ON registration(stack);
-CREATE INDEX h ON package(name);
+CREATE UNIQUE INDEX g ON repository_property(name);
+CREATE INDEX h ON registration(stack);
+CREATE INDEX i ON package(name);
View
@@ -34,5 +34,11 @@ is $pinto->config->log_level, 'debug', 'Got custom log_level';
is $pinto->config->sources, 'MySource', 'Got custom source';
#------------------------------------------------------------------------------
+# Test repository props
+
+my $ver = $pinto->repos->get_property('pinto:schema-version');
+is $ver, Pinto::Schema->version, 'Got pinto:schema-version prop';
+
+#------------------------------------------------------------------------------
done_testing;

0 comments on commit d4e1575

Please sign in to comment.