Permalink
Browse files

add schema

  • Loading branch information...
typester committed Dec 3, 2009
1 parent 1a4be88 commit 64d2bb18ffe2a09b2d1209db918abcb5a24ae98a
View
@@ -0,0 +1,9 @@
+package Jobeet::Schema;
+use strict;
+use warnings;
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_namespaces;
+
+1;
+
@@ -0,0 +1,53 @@
+package Jobeet::Schema::Result::Affiliate;
+use strict;
+use warnings;
+use base 'Jobeet::Schema::ResultBase';
+
+__PACKAGE__->table('jobeet_affiliate');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ is_auto_increment => 1,
+ extra => {
+ unsigned => 1,
+ },
+ },
+ url => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ email => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ token => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ is_active => {
+ data_type => 'TINYINT',
+ is_nullable => 0,
+ default_value => 0,
+ },
+ created_at => {
+ data_type => 'DATETIME',
+ is_nullable => 0,
+ timezone => 'Asia/Tokyo',
+ },
+);
+
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->add_unique_constraint(['email']);
+
+__PACKAGE__->has_many(
+ category_affiliate => 'Jobeet::Schema::Result::CategoryAffiliate', 'affiliate_id' );
+
+__PACKAGE__->many_to_many( categories => category_affiliate => 'category' );
+
+1;
+
@@ -0,0 +1,35 @@
+package Jobeet::Schema::Result::Category;
+use strict;
+use warnings;
+use base 'Jobeet::Schema::ResultBase';
+
+__PACKAGE__->table('jobeet_category');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ is_auto_increment => 1,
+ extra => {
+ unsigned => 1,
+ },
+ },
+ name => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+);
+
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->add_unique_constraint(['name']);
+
+__PACKAGE__->has_many( jobs => 'Jobeet::Schema::Result::Job', 'category_id' );
+
+__PACKAGE__->has_many(
+ category_affiliate => 'Jobeet::Schema::Result::CategoryAffiliate', 'category_id');
+
+__PACKAGE__->many_to_many( affiliates => category_affiliate => 'affiliate' );
+
+1;
+
@@ -0,0 +1,33 @@
+package Jobeet::Schema::Result::CategoryAffiliate;
+use strict;
+use warnings;
+use base 'Jobeet::Schema::ResultBase';
+
+__PACKAGE__->table('jobeet_category_affiliate');
+
+__PACKAGE__->add_columns(
+ category_id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ extra => {
+ unsigned => 1,
+ },
+ },
+ affiliate_id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ extra => {
+ unsigned => 1,
+ },
+ },
+);
+
+__PACKAGE__->set_primary_key(qw/category_id affiliate_id/);
+
+__PACKAGE__->belongs_to(
+ category => 'Jobeet::Schema::Result::Category', 'category_id' );
+__PACKAGE__->belongs_to(
+ affiliate => 'Jobeet::Schema::Result::Affiliate', 'affiliate_id' );
+
+1;
+
@@ -0,0 +1,90 @@
+package Jobeet::Schema::Result::Job;
+use strict;
+use warnings;
+use base 'Jobeet::Schema::ResultBase';
+
+__PACKAGE__->table('jobeet_job');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ is_auto_increment => 1,
+ extra => {
+ unsigned => 1,
+ },
+ },
+ category_id => {
+ data_type => 'INTEGER',
+ is_nullable => 0,
+ extra => {
+ unsigned => 1,
+ },
+ },
+ type => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 1,
+ },
+ position => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ location => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ description => {
+ data_type => 'TEXT',
+ is_nullable => 0,
+ },
+ how_to_apply => {
+ data_type => 'TEXT',
+ is_nullable => 0,
+ },
+ token => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ is_public => {
+ data_type => 'TINYINT',
+ is_nullable => 0,
+ default_value => 1,
+ },
+ is_activated => {
+ data_type => 'TINYINT',
+ is_nullable => 0,
+ default_value => 0,
+ },
+ email => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
+ expires_at => {
+ data_type => 'DATETIME',
+ is_nullable => 0,
+ timezone => 'Asia/Tokyo',
+ },
+ created_at => {
+ data_type => 'DATETIME',
+ is_nullable => 0,
+ timezone => 'Asia/Tokyo',
+ },
+ updated_at => {
+ data_type => 'DATETIME',
+ is_nullable => 0,
+ timezone => 'Asia/Tokyo',
+ },
+);
+
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->add_unique_constraint(['token']);
+
+__PACKAGE__->belongs_to( category => 'Jobeet::Schema::Result::Category', 'category_id' );
+
+
+1;
@@ -0,0 +1,31 @@
+package Jobeet::Schema::ResultBase;
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+use DateTime;
+
+__PACKAGE__->load_components(qw/InflateColumn::DateTime Core/);
+
+sub insert {
+ my $self = shift;
+
+ my $now = DateTime->now;
+ $self->created_at( $now ) if $self->can('created_at');
+ $self->updated_at( $now ) if $self->can('updated_at');
+
+ $self->next::method(@_);
+}
+
+sub update {
+ my $self = shift;
+
+ if ($self->can('updated_at')) {
+ $self->updated_at( DateTime->now );
+ }
+
+ $self->next::method(@_);
+}
+
+1;
+

0 comments on commit 64d2bb1

Please sign in to comment.