Browse files

day 04

  • Loading branch information...
1 parent 64d2bb1 commit 845b6b8557042b71f68687f80ea6c4cd75ded358 @typester committed Dec 4, 2009
View
2 .gitignore
@@ -0,0 +1,2 @@
+config_local.pl
+database.db
View
11 config.pl
@@ -0,0 +1,11 @@
+my $home = Jobeet::Models->get('home');
+
+return {
+ database => [
+ 'dbi:SQLite:' . $home->file('database.db'), '', '',
+ {
+ unicode => 1,
+ sqlite_unicode => 1,
+ },
+ ],
+};
View
2 lib/Jobeet.pm
@@ -3,4 +3,6 @@ use Ark;
our $VERSION = '0.01';
+use_model 'Jobeet::Models';
+
1;
View
24 lib/Jobeet/Models.pm
@@ -0,0 +1,24 @@
+package Jobeet::Models;
+use strict;
+use warnings;
+use Ark::Models '-base';
+
+register Schema => sub {
+ my $self = shift;
+
+ my $conf = $self->get('conf')->{database}
+ or die 'require database config';
+
+ $self->ensure_class_loaded('Jobeet::Schema');
+ Jobeet::Schema->connect(@$conf);
+};
+
+for my $table (qw/Job Category CategoryAffiliate Affiliate/) {
+ register "Schema::$table" => sub {
+ my $self = shift;
+ $self->get('Schema')->resultset($table);
+ };
+}
+
+1;
+
View
5 lib/Jobeet/Schema.pm
@@ -3,7 +3,12 @@ use strict;
use warnings;
use base 'DBIx::Class::Schema';
+our $VERSION = '2';
+
__PACKAGE__->load_namespaces;
+__PACKAGE__->load_components('Schema::Versioned');
+__PACKAGE__->upgrade_directory('sql/');
+
1;
View
15 lib/Jobeet/Schema/Result/Job.pm
@@ -26,6 +26,21 @@ __PACKAGE__->add_columns(
size => 255,
is_nullable => 1,
},
+ company => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 1,
+ },
+ logo => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 1,
+ },
+ url => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 1,
+ },
position => {
data_type => 'VARCHAR',
size => 255,
View
BIN root/uploads/jobs/extreme-sensio.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN root/uploads/jobs/sensio-labs.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
30 script/create_ddl.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin::libs;
+use Path::Class qw/file/;
+
+use Jobeet::Models;
+
+my $schema = models('Schema');
+
+my $current_version = $schema->schema_version;
+my $next_version = $current_version + 1;
+
+$schema->create_ddl_dir(
+ [qw/SQLite MySQL/],
+ $next_version,
+ "$FindBin::Bin/../sql/",
+);
+
+{ # replace version
+ my $f = file( $INC{'Jobeet/Schema.pm'} );
+ my $content = $f->slurp;
+ $content =~ s/(\$VERSION\s*=\s*(['"]))(.+?)\2/$1$next_version$2/
+ or die "Failed to replace version.";
+
+ my $fh = $f->openw or die $!;
+ print $fh $content;
+ $fh->close;
+}
View
50 script/insert_default_data.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin::libs;
+
+use Jobeet::Models;
+
+# create default Categories
+for my $category_name (qw/Design Programming Manager Administrator/) {
+ models('Schema::Category')->create({ name => $category_name });
+}
+
+# create default Jobs
+my $programming_category =
+ models('Schema::Category')->find({ name => 'Programming' });
+$programming_category->add_to_jobs({
+ type => 'full-time',
+ company => 'Sensio Labs',
+ logo => 'sensio-labs.gif',
+ url => 'http://www.sensiolabs.com/',
+ position => 'Web Developer',
+ location => 'Paris, France',
+ description => q[You've already developed websites with symfony and you want to work with Open-Source technologies. You have a minimum of 3 years experience in web development with PHP or Java and you wish to participate to development of Web 2.0 sites using the best frameworks available.],
+ how_to_apply => 'Send your resume to fabien.potencier [at] sensio.com',
+ is_public => 1,
+ is_activated => 1,
+ token => 'job_sensio_labs',
+ email => 'job@example.com',
+ expires_at => '2010-10-10',
+});
+
+my $design_category = models('Schema::Category')->find({ name => 'Design' });
+$design_category->add_to_jobs({
+ type => 'part-time',
+ company => 'Extreme Sensio',
+ logo => 'extreme-sensio.gif',
+ url => 'http://www.extreme-sensio.com/',
+ position => 'Web Designer',
+ location => 'Paris, France',
+ description => q[Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Utenim ad minim veniam, quis nostrud exercitation ullamco laborisnisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in. Voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpaqui officia deserunt mollit anim id est laborum.],
+ how_to_apply => 'Send your resume to fabien.potencier [at] sensio.com',
+ is_public => 1,
+ is_activated => 1,
+ token => 'job_extreme_sensio',
+ email => 'job@example.com',
+ expires_at => '2010-10-10',
+});
+
+
View
91 script/upgrade_database.pl
@@ -0,0 +1,91 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin::libs;
+use Path::Class 'file';
+
+use Getopt::Long;
+
+GetOptions(
+ \my %options,
+ qw/dry-run/
+);
+
+use SQL::Translator;
+use SQL::Translator::Diff;
+
+use Jobeet::Models;
+
+my $schema = models('Schema');
+
+my $sqltargs = {
+ add_drop_table => 1,
+ ignore_constraint_names => 1,
+ ignore_index_names => 1,
+};
+
+sub parse_sql {
+ my ($file, $type) = @_;
+
+ my $t = SQL::Translator->new($sqltargs);
+
+ $t->parser($type)
+ or die $t->error;
+
+ my $out = $t->translate("$file")
+ or die $t->error;
+
+ my $schema = $t->schema;
+
+ $schema->name( $file->basename )
+ unless ( $schema->name );
+
+ $schema;
+}
+
+no warnings 'redefine', 'once';
+my $upgrade_file;
+local *Jobeet::Schema::create_upgrade_path = sub {
+ $upgrade_file = $_[1]->{upgrade_file};
+
+ my $current_version = $schema->get_db_version;
+ my $schema_version = $schema->schema_version;
+ my $database = $schema->storage->sqlt_type;
+ my $dir = $schema->upgrade_directory;
+
+ my $prev_file = $schema->ddl_filename($database, $current_version, $dir);
+ my $next_file = $schema->ddl_filename($database, $schema_version, $dir);
+
+ my $current_schema = eval { parse_sql file($prev_file), $database } or die $@;
+ my $next_schema = eval { parse_sql file($next_file), $database } or die $@;
+
+ my $diff = SQL::Translator::Diff::schema_diff(
+ $current_schema, $database,
+ $next_schema, $database,
+ $sqltargs,
+ );
+
+ if ($upgrade_file) {
+ my $fh = file($upgrade_file)->openw or die $!;
+ print $fh $diff;
+ $fh->close;
+ }
+ else {
+ print $diff;
+ }
+};
+
+if ($schema->get_db_version) {
+ if ($options{'dry-run'}) {
+ $schema->create_upgrade_path;
+ }
+ else {
+ $schema->upgrade;
+ unlink $upgrade_file if $upgrade_file;
+ }
+}
+else {
+ $schema->deploy;
+}
+
View
77 sql/Jobeet-Schema-1-MySQL.sql
@@ -0,0 +1,77 @@
+--
+-- Created by SQL::Translator::Producer::MySQL
+-- Created on Fri Dec 4 19:34:03 2009
+--
+SET foreign_key_checks=0;
+
+DROP TABLE IF EXISTS `jobeet_affiliate`;
+
+--
+-- Table: `jobeet_affiliate`
+--
+CREATE TABLE `jobeet_affiliate` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `url` VARCHAR(255) NOT NULL,
+ `email` VARCHAR(255) NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_active` TINYINT NOT NULL DEFAULT '0',
+ `created_at` datetime NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_affiliate_email` (`email`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category`;
+
+--
+-- Table: `jobeet_category`
+--
+CREATE TABLE `jobeet_category` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `name` VARCHAR(255) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_category_name` (`name`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_job`;
+
+--
+-- Table: `jobeet_job`
+--
+CREATE TABLE `jobeet_job` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `category_id` INTEGER unsigned NOT NULL,
+ `type` VARCHAR(255),
+ `position` VARCHAR(255) NOT NULL,
+ `location` VARCHAR(255) NOT NULL,
+ `description` text NOT NULL,
+ `how_to_apply` text NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_public` TINYINT NOT NULL DEFAULT '1',
+ `is_activated` TINYINT NOT NULL DEFAULT '0',
+ `email` VARCHAR(255) NOT NULL,
+ `expires_at` datetime NOT NULL,
+ `created_at` datetime NOT NULL,
+ `updated_at` datetime NOT NULL,
+ INDEX jobeet_job_idx_category_id (`category_id`),
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_job_token` (`token`),
+ CONSTRAINT `jobeet_job_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category_affiliate`;
+
+--
+-- Table: `jobeet_category_affiliate`
+--
+CREATE TABLE `jobeet_category_affiliate` (
+ `category_id` INTEGER unsigned NOT NULL,
+ `affiliate_id` INTEGER unsigned NOT NULL,
+ INDEX jobeet_category_affiliate_idx_affiliate_id (`affiliate_id`),
+ INDEX jobeet_category_affiliate_idx_category_id (`category_id`),
+ PRIMARY KEY (`category_id`, `affiliate_id`),
+ CONSTRAINT `jobeet_category_affiliate_fk_affiliate_id` FOREIGN KEY (`affiliate_id`) REFERENCES `jobeet_affiliate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `jobeet_category_affiliate_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+SET foreign_key_checks=1;
+
View
78 sql/Jobeet-Schema-1-SQLite.sql
@@ -0,0 +1,78 @@
+--
+-- Created by SQL::Translator::Producer::SQLite
+-- Created on Fri Dec 4 19:34:03 2009
+--
+
+
+BEGIN TRANSACTION;
+
+--
+-- Table: jobeet_affiliate
+--
+DROP TABLE jobeet_affiliate;
+
+CREATE TABLE jobeet_affiliate (
+ id INTEGER PRIMARY KEY NOT NULL,
+ url VARCHAR(255) NOT NULL,
+ email VARCHAR(255) NOT NULL,
+ token VARCHAR(255) NOT NULL,
+ is_active TINYINT NOT NULL DEFAULT '0',
+ created_at DATETIME NOT NULL
+);
+
+CREATE UNIQUE INDEX jobeet_affiliate_email ON jobeet_affiliate (email);
+
+--
+-- Table: jobeet_category
+--
+DROP TABLE jobeet_category;
+
+CREATE TABLE jobeet_category (
+ id INTEGER PRIMARY KEY NOT NULL,
+ name VARCHAR(255) NOT NULL
+);
+
+CREATE UNIQUE INDEX jobeet_category_name ON jobeet_category (name);
+
+--
+-- Table: jobeet_job
+--
+DROP TABLE jobeet_job;
+
+CREATE TABLE jobeet_job (
+ id INTEGER PRIMARY KEY NOT NULL,
+ category_id INTEGER NOT NULL,
+ type VARCHAR(255),
+ position VARCHAR(255) NOT NULL,
+ location VARCHAR(255) NOT NULL,
+ description TEXT NOT NULL,
+ how_to_apply TEXT NOT NULL,
+ token VARCHAR(255) NOT NULL,
+ is_public TINYINT NOT NULL DEFAULT '1',
+ is_activated TINYINT NOT NULL DEFAULT '0',
+ email VARCHAR(255) NOT NULL,
+ expires_at DATETIME NOT NULL,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL
+);
+
+CREATE INDEX jobeet_job_idx_category_id ON jobeet_job (category_id);
+
+CREATE UNIQUE INDEX jobeet_job_token ON jobeet_job (token);
+
+--
+-- Table: jobeet_category_affiliate
+--
+DROP TABLE jobeet_category_affiliate;
+
+CREATE TABLE jobeet_category_affiliate (
+ category_id INTEGER NOT NULL,
+ affiliate_id INTEGER NOT NULL,
+ PRIMARY KEY (category_id, affiliate_id)
+);
+
+CREATE INDEX jobeet_category_affiliate_idx_affiliate_id ON jobeet_category_affiliate (affiliate_id);
+
+CREATE INDEX jobeet_category_affiliate_idx_category_id ON jobeet_category_affiliate (category_id);
+
+COMMIT;
View
80 sql/Jobeet-Schema-2-MySQL.sql
@@ -0,0 +1,80 @@
+--
+-- Created by SQL::Translator::Producer::MySQL
+-- Created on Fri Dec 4 19:44:59 2009
+--
+SET foreign_key_checks=0;
+
+DROP TABLE IF EXISTS `jobeet_affiliate`;
+
+--
+-- Table: `jobeet_affiliate`
+--
+CREATE TABLE `jobeet_affiliate` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `url` VARCHAR(255) NOT NULL,
+ `email` VARCHAR(255) NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_active` TINYINT NOT NULL DEFAULT '0',
+ `created_at` datetime NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_affiliate_email` (`email`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category`;
+
+--
+-- Table: `jobeet_category`
+--
+CREATE TABLE `jobeet_category` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `name` VARCHAR(255) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_category_name` (`name`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_job`;
+
+--
+-- Table: `jobeet_job`
+--
+CREATE TABLE `jobeet_job` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `category_id` INTEGER unsigned NOT NULL,
+ `type` VARCHAR(255),
+ `company` VARCHAR(255),
+ `logo` VARCHAR(255),
+ `url` VARCHAR(255),
+ `position` VARCHAR(255) NOT NULL,
+ `location` VARCHAR(255) NOT NULL,
+ `description` text NOT NULL,
+ `how_to_apply` text NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_public` TINYINT NOT NULL DEFAULT '1',
+ `is_activated` TINYINT NOT NULL DEFAULT '0',
+ `email` VARCHAR(255) NOT NULL,
+ `expires_at` datetime NOT NULL,
+ `created_at` datetime NOT NULL,
+ `updated_at` datetime NOT NULL,
+ INDEX jobeet_job_idx_category_id (`category_id`),
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_job_token` (`token`),
+ CONSTRAINT `jobeet_job_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category_affiliate`;
+
+--
+-- Table: `jobeet_category_affiliate`
+--
+CREATE TABLE `jobeet_category_affiliate` (
+ `category_id` INTEGER unsigned NOT NULL,
+ `affiliate_id` INTEGER unsigned NOT NULL,
+ INDEX jobeet_category_affiliate_idx_affiliate_id (`affiliate_id`),
+ INDEX jobeet_category_affiliate_idx_category_id (`category_id`),
+ PRIMARY KEY (`category_id`, `affiliate_id`),
+ CONSTRAINT `jobeet_category_affiliate_fk_affiliate_id` FOREIGN KEY (`affiliate_id`) REFERENCES `jobeet_affiliate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `jobeet_category_affiliate_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+SET foreign_key_checks=1;
+
View
81 sql/Jobeet-Schema-2-SQLite.sql
@@ -0,0 +1,81 @@
+--
+-- Created by SQL::Translator::Producer::SQLite
+-- Created on Fri Dec 4 19:44:59 2009
+--
+
+
+BEGIN TRANSACTION;
+
+--
+-- Table: jobeet_affiliate
+--
+DROP TABLE jobeet_affiliate;
+
+CREATE TABLE jobeet_affiliate (
+ id INTEGER PRIMARY KEY NOT NULL,
+ url VARCHAR(255) NOT NULL,
+ email VARCHAR(255) NOT NULL,
+ token VARCHAR(255) NOT NULL,
+ is_active TINYINT NOT NULL DEFAULT '0',
+ created_at DATETIME NOT NULL
+);
+
+CREATE UNIQUE INDEX jobeet_affiliate_email ON jobeet_affiliate (email);
+
+--
+-- Table: jobeet_category
+--
+DROP TABLE jobeet_category;
+
+CREATE TABLE jobeet_category (
+ id INTEGER PRIMARY KEY NOT NULL,
+ name VARCHAR(255) NOT NULL
+);
+
+CREATE UNIQUE INDEX jobeet_category_name ON jobeet_category (name);
+
+--
+-- Table: jobeet_job
+--
+DROP TABLE jobeet_job;
+
+CREATE TABLE jobeet_job (
+ id INTEGER PRIMARY KEY NOT NULL,
+ category_id INTEGER NOT NULL,
+ type VARCHAR(255),
+ company VARCHAR(255),
+ logo VARCHAR(255),
+ url VARCHAR(255),
+ position VARCHAR(255) NOT NULL,
+ location VARCHAR(255) NOT NULL,
+ description TEXT NOT NULL,
+ how_to_apply TEXT NOT NULL,
+ token VARCHAR(255) NOT NULL,
+ is_public TINYINT NOT NULL DEFAULT '1',
+ is_activated TINYINT NOT NULL DEFAULT '0',
+ email VARCHAR(255) NOT NULL,
+ expires_at DATETIME NOT NULL,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL
+);
+
+CREATE INDEX jobeet_job_idx_category_id ON jobeet_job (category_id);
+
+CREATE UNIQUE INDEX jobeet_job_token ON jobeet_job (token);
+
+--
+-- Table: jobeet_category_affiliate
+--
+DROP TABLE jobeet_category_affiliate;
+
+CREATE TABLE jobeet_category_affiliate (
+ category_id INTEGER NOT NULL,
+ affiliate_id INTEGER NOT NULL,
+ PRIMARY KEY (category_id, affiliate_id)
+);
+
+CREATE INDEX jobeet_category_affiliate_idx_affiliate_id ON jobeet_category_affiliate (affiliate_id);
+
+CREATE INDEX jobeet_category_affiliate_idx_category_id ON jobeet_category_affiliate (category_id);
+
+COMMIT;

0 comments on commit 845b6b8

Please sign in to comment.