diff options
-rwxr-xr-x | db/rerun_dbic_loader.pl | 34 | ||||
-rw-r--r-- | db/schema_0001.sql | 36 |
2 files changed, 70 insertions, 0 deletions
diff --git a/db/rerun_dbic_loader.pl b/db/rerun_dbic_loader.pl new file mode 100755 index 000000000..241a4726b --- /dev/null +++ b/db/rerun_dbic_loader.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# This script inspects the current state of the database and then ammends the +# FixMyStreet::DB::Result::* files to suit. After running the changes should be +# inspected before the code is commited. + +use FixMyStreet; +use DBIx::Class::Schema::Loader qw/ make_schema_at /; + +# create a exclude statement that filters out the table that we are not +# interested in +my @tables_to_ignore = ( + 'abuse', 'admin_log', 'alert', 'alert_sent', + 'alert_type', 'comment', 'contacts', 'contacts_history', + 'debugdate', 'flickr_imported', 'partial_user', 'problem', + 'questionnaire', 'secret', 'textmystreet', 'token', +); +my $exclude = '^(?:' . join( '|', @tables_to_ignore ) . ')$'; + +make_schema_at( + 'FixMyStreet::DB', + { + debug => 0, # switch on to be chatty + dump_directory => './lib', # edit files in place + exclude => qr{$exclude}, # ignore some tables + generate_pod => 0, # no need for pod + overwrite_modifications => 1, # don't worry that the md5 is wrong + }, + FixMyStreet->dbic_connect_info(), +); + diff --git a/db/schema_0001.sql b/db/schema_0001.sql new file mode 100644 index 000000000..88bed06c6 --- /dev/null +++ b/db/schema_0001.sql @@ -0,0 +1,36 @@ +-- These are changes needed to the schema to support moving over to DBIx::Class + +begin; + +-- table for sessions - needed by Catalyst::Plugin::Session::Store::DBIC +CREATE TABLE sessions ( + id CHAR(72) PRIMARY KEY, + session_data TEXT, + expires INTEGER +); + +-- users table +create table users ( + id serial not null primary key, + email text not null unique, + name text, + password text not null +); + +-- add PK to contacts table +ALTER TABLE contacts + ADD COLUMN id SERIAL PRIMARY KEY; + +AlTER TABLE contacts_history + ADD COLUMN contact_id integer; + +update contacts_history + set contact_id = ( + select id + from contacts + where contacts_history.category = contacts.category + and contacts_history.area_id = contacts.area_id + ); + +-- rollback; +commit; |