Skip to content

Commit

Permalink
Add fixtures and schema fixes
Browse files Browse the repository at this point in the history
This fixes Vagrant, which previously required a checkout of the
last valid version of `etc/schema.sql`. Django now drives table
creation and we fix it up for Flourish afterwards.

As we have `USE_TZ = True`, Django will create DateTime columns as
`timestamp with time zone`. We just need to make sure we only use
UTC until all Flourish code is removed.
  • Loading branch information
marksteward committed Aug 4, 2017
1 parent c120da2 commit 6f3acf4
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 7 deletions.
11 changes: 5 additions & 6 deletions bootstrap.sh
Expand Up @@ -34,9 +34,6 @@ EOF

service postgresql reload

psql -U hackspace hackspace < /var/www/hackspace-foundation-sites/etc/schema.sql
psql -U hackspace hackspace < /var/www/hackspace-foundation-sites/etc/create-flourish-tables.sql

# Configure php
sed -i~ -e "s/short_open_tag = Off/short_open_tag = On/" \
-e "s/display_errors = Off/display_errors = On/" \
Expand All @@ -62,10 +59,12 @@ cd /var/www/hackspace-foundation-sites
su vagrant -c 'virtualenv -p python3 --always-copy vagrant-env'
su vagrant -c 'vagrant-env/bin/pip install -r requirements.txt'

su vagrant -c 'vagrant-env/bin/python manage.py migrate main 0001 --fake-initial'
su vagrant -c 'vagrant-env/bin/python manage.py migrate main 0002'
su vagrant -c 'vagrant-env/bin/python manage.py migrate main 0003 --fake'
su vagrant -c 'vagrant-env/bin/python manage.py migrate'
su vagrant -c 'vagrant-env/bin/python manage.py loaddata main/fixtures/*'

psql -U hackspace hackspace < /var/www/hackspace-foundation-sites/etc/create-flourish-tables.sql
psql -U hackspace hackspace < /var/www/hackspace-foundation-sites/etc/restore-column-defaults.sql
psql -U hackspace hackspace < /var/www/hackspace-foundation-sites/etc/restore-multicolumn-pks.sql


cat > /home/vagrant/.bash_profile <<EOF
Expand Down
28 changes: 27 additions & 1 deletion etc/create-flourish-tables.sql
@@ -1,5 +1,31 @@
begin;

create table flourish_tables (
tablename name
);
insert into flourish_tables select tablename from pg_tables where tableowner = 'hackspace' order by tablename;

copy flourish_tables (tablename) from stdin;
aliases
cards
interests
interests_categories
learnings
locations
meeting_attendees
password_resets
perms
project_states
projects
projects_logs
proxy_votes
subscriptions
transactions
userperms
users
users_aliases
users_interests
users_learnings
users_profiles
\.

commit;
34 changes: 34 additions & 0 deletions etc/restore-column-defaults.sql
@@ -0,0 +1,34 @@
-- Restores defaults on columns for Flourish
-- Django migrations can force defaults to be removed.
-- This should be safe to run at any time to clean up.

begin;

alter table "users"
alter subscribed set default false,
alter hackney set default false,
alter subscription_period set default 0,
alter terminated set default false,
alter admin set default false,
alter has_profile set default false,
alter disabled_profile set default false
;

alter table cards
alter active set default true
;

alter table users_profiles
alter allow_email set default false,
alter allow_doorbot set default false
;

alter table aliases
alter type set default 2
;

alter table interests
alter suggested set default false
;

commit;
16 changes: 16 additions & 0 deletions etc/restore-multicolumn-pks.sql
@@ -0,0 +1,16 @@
-- Restores multi-column primary keys for Flourish
-- Django doesn't understand multi-column primary keys yet.
-- This should only need to be run after initial migration.

begin;

alter table users_learnings drop column if exists id;
alter table users_learnings add primary key (user_id, learning_id);

alter table users_aliases drop column if exists id;
alter table users_aliases add primary key (user_id, alias_id);

alter table users_interests drop column if exists id;
alter table users_interests add primary key (user_id, interest_id);

commit;
42 changes: 42 additions & 0 deletions main/fixtures/Alias.yaml
@@ -0,0 +1,42 @@
- model: main.alias
pk: Callsign
fields: {type: 2}
- model: main.alias
pk: Ello
fields: {type: 2}
- model: main.alias
pk: Facebook
fields: {type: 2}
- model: main.alias
pk: Flickr
fields: {type: 2}
- model: main.alias
pk: GitHub
fields: {type: 2}
- model: main.alias
pk: Google+
fields: {type: 2}
- model: main.alias
pk: Hackspace Wiki
fields: {type: 1}
- model: main.alias
pk: IRC
fields: {type: 1}
- model: main.alias
pk: LinkedIn
fields: {type: 2}
- model: main.alias
pk: Minecraft
fields: {type: 2}
- model: main.alias
pk: RSS
fields: {type: 2}
- model: main.alias
pk: Twitter
fields: {type: 2}
- model: main.alias
pk: XMPP/Jabber
fields: {type: 2}
- model: main.alias
pk: YouTube
fields: {type: 2}
87 changes: 87 additions & 0 deletions main/fixtures/Interest.yaml
@@ -0,0 +1,87 @@
- model: main.interest
pk: 1
fields: {category: Computing, suggested: true, name: Robotics, url: 'https://wiki.london.hackspace.org.uk/view/Robotics'}
- model: main.interest
pk: 2
fields: {category: Computing, suggested: true, name: Arduino, url: 'https://wiki.london.hackspace.org.uk/view/Not_Just_Arduino'}
- model: main.interest
pk: 3
fields: {category: Computing, suggested: true, name: Raspberry Pi, url: 'https://wiki.london.hackspace.org.uk/view/Not_Just_Arduino'}
- model: main.interest
pk: 4
fields: {category: Computing, suggested: true, name: Soldering, url: 'https://wiki.london.hackspace.org.uk/view/Electronics_Area'}
- model: main.interest
pk: 5
fields: {category: Computing, suggested: true, name: Hardware, url: 'https://wiki.london.hackspace.org.uk/view/Not_Just_Arduino'}
- model: main.interest
pk: 6
fields: {category: Computing, suggested: true, name: Software, url: 'https://wiki.london.hackspace.org.uk/w/index.php?title=Special%3ASearch&search=software'}
- model: main.interest
pk: 7
fields: {category: Computing, suggested: true, name: Programming, url: 'https://wiki.london.hackspace.org.uk/w/index.php?title=Special%3ASearch&search=programming&go=Go'}
- model: main.interest
pk: 8
fields: {category: Fabrication, suggested: true, name: 3D printing, url: 'https://wiki.london.hackspace.org.uk/view/Equipment/Lulzbot_a0_101'}
- model: main.interest
pk: 9
fields: {category: Fabrication, suggested: true, name: Laser cutting, url: 'https://wiki.london.hackspace.org.uk/view/Laser_Cutter'}
- model: main.interest
pk: 10
fields: {category: Fabrication, suggested: true, name: CNC routing, url: 'https://wiki.london.hackspace.org.uk/view/Pledge:_CNC_Mill'}
- model: main.interest
pk: 11
fields: {category: Fabrication, suggested: true, name: Woodworking, url: 'https://wiki.london.hackspace.org.uk/view/Dusty_Wood_Shop'}
- model: main.interest
pk: 12
fields: {category: Fabrication, suggested: true, name: Metalworking, url: 'https://wiki.london.hackspace.org.uk/view/Dirty_Metal_Shop'}
- model: main.interest
pk: 13
fields: {category: Fabrication, suggested: true, name: Welding, url: 'https://wiki.london.hackspace.org.uk/view/Welding_Training'}
- model: main.interest
pk: 14
fields: {category: Crafts, suggested: true, name: Sewing, url: 'https://wiki.london.hackspace.org.uk/view/Sewing_Machines'}
- model: main.interest
pk: 15
fields: {category: Crafts, suggested: true, name: Knitting, url: 'https://wiki.london.hackspace.org.uk/view/Equipment/Knitting_Machine'}
- model: main.interest
pk: 16
fields: {category: Crafts, suggested: true, name: Painting, url: 'https://wiki.london.hackspace.org.uk/view/Hackspace_Art'}
- model: main.interest
pk: 17
fields: {category: Crafts, suggested: true, name: Sculpting, url: 'https://wiki.london.hackspace.org.uk/view/Hackspace_Art'}
- model: main.interest
pk: 18
fields: {category: Crafts, suggested: true, name: Vinyl cutting, url: 'https://wiki.london.hackspace.org.uk/view/Vinyl_cutter'}
- model: main.interest
pk: 19
fields: {category: Special interests, suggested: true, name: Amateur radio, url: 'https://wiki.london.hackspace.org.uk/view/Amateur_Radio'}
- model: main.interest
pk: 20
fields: {category: Special interests, suggested: true, name: Lock picking, url: 'https://wiki.london.hackspace.org.uk/view/Project:Lockpicking'}
- model: main.interest
pk: 21
fields: {category: Special interests, suggested: true, name: Music hacking, url: 'https://wiki.london.hackspace.org.uk/view/Music_Hack_Space'}
- model: main.interest
pk: 22
fields: {category: Special interests, suggested: true, name: Photography, url: 'https://wiki.london.hackspace.org.uk/view/Project:Darkroom'}
- model: main.interest
pk: 23
fields: {category: Special interests, suggested: true, name: Biohacking, url: 'https://wiki.london.hackspace.org.uk/view/Biohacking'}
- model: main.interest
pk: 24
fields: {category: Special interests, suggested: true, name: LAN gaming, url: 'https://wiki.london.hackspace.org.uk/view/London_FRAGspace'}
- model: main.interest
pk: 25
fields: {category: Special interests, suggested: true, name: PL(A)YWOOD, url: 'https://wiki.london.hackspace.org.uk/view/Playwood'}
- model: main.interest
pk: 26
fields: {category: Special interests, suggested: true, name: Brewing, url: 'https://wiki.london.hackspace.org.uk/view/Brewing'}
- model: main.interest
pk: 27
fields: {category: Special interests, suggested: true, name: Gardening, url: 'https://wiki.london.hackspace.org.uk/view/Garden'}
- model: main.interest
pk: 28
fields: {category: Special interests, suggested: true, name: Cycling, url: 'https://wiki.london.hackspace.org.uk/w/index.php?title=Special%3ASearch&search=cycling&go=Go'}
- model: main.interest
pk: 29
fields: {category: Special interests, suggested: true, name: Aerospace, url: 'https://wiki.london.hackspace.org.uk/view/LondonAerospace'}
15 changes: 15 additions & 0 deletions main/fixtures/InterestCategory.yaml
@@ -0,0 +1,15 @@
- model: main.interestcategory
pk: Computing
fields: {}
- model: main.interestcategory
pk: Crafts
fields: {}
- model: main.interestcategory
pk: Fabrication
fields: {}
- model: main.interestcategory
pk: Other
fields: {}
- model: main.interestcategory
pk: Special interests
fields: {}
9 changes: 9 additions & 0 deletions main/fixtures/Learning.yaml
@@ -0,0 +1,9 @@
- model: main.learning
pk: 1
fields: {name: Laser cutting, description: Laser cutter trained, url: 'https://wiki.london.hackspace.org.uk/view/Lasercutter_Training'}
- model: main.learning
pk: 2
fields: {name: Vinyl cutting, description: Vinyl cutter trained, url: 'https://wiki.london.hackspace.org.uk/view/Equipment/VinylCutter'}
- model: main.learning
pk: 3
fields: {name: 3D printing, description: 3D printer trained, url: 'https://wiki.london.hackspace.org.uk/view/3dprinter_training'}
9 changes: 9 additions & 0 deletions main/fixtures/Location.yaml
@@ -0,0 +1,9 @@
- model: main.location
pk: 1
fields: {name: Ground floor}
- model: main.location
pk: 2
fields: {name: Basement}
- model: main.location
pk: 3
fields: {name: Yard}
21 changes: 21 additions & 0 deletions main/fixtures/ProjectStates.yaml
@@ -0,0 +1,21 @@
- model: main.projectstates
pk: 1
fields: {name: Pending Approval}
- model: main.projectstates
pk: 2
fields: {name: Approved}
- model: main.projectstates
pk: 3
fields: {name: Unapproved}
- model: main.projectstates
pk: 4
fields: {name: Extended}
- model: main.projectstates
pk: 5
fields: {name: Passed Deadline}
- model: main.projectstates
pk: 6
fields: {name: Removed}
- model: main.projectstates
pk: 7
fields: {name: Archived}
2 changes: 2 additions & 0 deletions requirements.txt
Expand Up @@ -2,3 +2,5 @@ Django==1.11.3
psycopg2==2.7.1
requests==2.18.1
msgpack-python==0.4.8
pytz==2017.2
PyYAML==3.12

0 comments on commit 6f3acf4

Please sign in to comment.