From: Thierry Parmentelat Date: Tue, 29 Nov 2011 14:29:58 +0000 (+0100) Subject: ship database schema in a separate file X-Git-Tag: sfa-2.0-1~3^2~5 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=45f5ad180c84c1462cfc5e3c8574318e2d121b2d;p=sfa.git ship database schema in a separate file --- diff --git a/init.d/sfa b/init.d/sfa index 92c70ea2..a3cd5447 100755 --- a/init.d/sfa +++ b/init.d/sfa @@ -208,8 +208,10 @@ function db_start () { # db if ! psql -U $SFA_DB_USER -c "" $SFA_DB_NAME >/dev/null 2>&1 ; then createdb -U postgres --template=template0 --encoding=UNICODE --owner=$SFA_DB_USER $SFA_DB_NAME + check # xxx in case we'd like to ship the db schema separately - #psql -U $SFA_DB_USER -f /etc/sfa/or/someplace/else/sfa.sql $SFA_DB_NAME + psql -U $SFA_DB_USER -f /usr/share/sfa/sfa.sql $SFA_DB_NAME + check fi check @@ -243,21 +245,14 @@ function start() { # install peer certs action $"SFA installing peer certs" daemon /usr/bin/sfa-start.py -t -d $OPTIONS - if [ "$SFA_REGISTRY_ENABLED" -eq 1 ]; then - action $"SFA Registry" daemon /usr/bin/sfa-start.py -r -d $OPTIONS - fi - - if [ "$SFA_AGGREGATE_ENABLED" -eq 1 ]; then - action $"SFA Aggregate" daemon /usr/bin/sfa-start.py -a -d $OPTIONS - fi + [ "$SFA_REGISTRY_ENABLED" == 1 ] && action $"SFA Registry" daemon /usr/bin/sfa-start.py -r -d $OPTIONS + + [ "$SFA_AGGREGATE_ENABLED" == 1 ] && action $"SFA Aggregate" daemon /usr/bin/sfa-start.py -a -d $OPTIONS - if [ "$SFA_SM_ENABLED" -eq 1 ]; then - action "SFA SliceMgr" daemon /usr/bin/sfa-start.py -s -d $OPTIONS - fi + [ "$SFA_SM_ENABLED" == 1 ] && action "SFA SliceMgr" daemon /usr/bin/sfa-start.py -s -d $OPTIONS - if [ "$SFA_FLASHPOLICY_ENABLED" -eq 1 ]; then + [ "$SFA_FLASHPOLICY_ENABLED" == 1 ] && \ action "Flash Policy Server" daemon /usr/bin/sfa_flashpolicy.py --file="$SFA_FLASHPOLICY_CONFIG_FILE" --port=$SFA_FLASHPOLICY_PORT -d - fi touch /var/lock/subsys/sfa-start.py diff --git a/setup.py b/setup.py index c0a8b9ed..9f68e18e 100755 --- a/setup.py +++ b/setup.py @@ -73,7 +73,9 @@ data_files = [('/etc/sfa/', [ 'config/aggregates.xml', ]), ('/etc/sfatables/matches/', glob('sfatables/matches/*.xml')), ('/etc/sfatables/targets/', glob('sfatables/targets/*.xml')), - ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ])] + ('/etc/init.d/', [ "init.d/%s"%x for x in initscripts ]), + ('/usr/share/sfa/', [ 'sfa/storage/sfa.sql' ] ), + ] # add sfatables processors as data_files processor_files = [f for f in glob('sfatables/processors/*') if os.path.isfile(f)] diff --git a/sfa.spec b/sfa.spec index 9fd9cc96..a96d177c 100644 --- a/sfa.spec +++ b/sfa.spec @@ -125,6 +125,8 @@ make VERSIONTAG="%{version}-%{taglevel}" SCMURL="%{SCMURL}" rm -rf $RPM_BUILD_ROOT make VERSIONTAG="%{version}-%{taglevel}" SCMURL="%{SCMURL}" install DESTDIR="$RPM_BUILD_ROOT" rm -rf $RPM_BUILD_ROOT/%{python_sitelib}/*egg-info +# this gets duplicated +rm -rf $RPM_BUILD_ROOT/usr/share/sfa/sfa.sql %clean rm -rf $RPM_BUILD_ROOT @@ -140,6 +142,7 @@ rm -rf $RPM_BUILD_ROOT %config /etc/sfa/default_config.xml %config (noreplace) /etc/sfa/aggregates.xml %config (noreplace) /etc/sfa/registries.xml +/usr/share/sfa/sfa.sql /var/www/html/wsdl/*.wsdl %files plc diff --git a/sfa/storage/sfa.sql b/sfa/storage/sfa.sql new file mode 100644 index 00000000..3d7984d1 --- /dev/null +++ b/sfa/storage/sfa.sql @@ -0,0 +1,55 @@ +-- +-- SFA database schema +-- + +SET client_encoding = 'UNICODE'; + +-------------------------------------------------------------------------------- +-- Version +-------------------------------------------------------------------------------- + +-- Database version +CREATE TABLE sfa_db_version ( + version integer NOT NULL, + subversion integer NOT NULL DEFAULT 0 +) WITH OIDS; + +-- the migration scripts do not use the major 'version' number +-- so 5.0 sets subversion at 100 +-- in case your database misses the site and persons tags feature, +-- you might wish to first upgrade to 4.3-rc16 before moving to some 5.0 +-- or run the up script here +-- http://svn.planet-lab.org/svn/PLCAPI/branches/4.3/migrations/ + +INSERT INTO sfa_db_version (version, subversion) VALUES (1, 1); + +-------------------------------------------------------------------------------- +-- Aggregates and store procedures +-------------------------------------------------------------------------------- + +-- Like MySQL GROUP_CONCAT(), this function aggregates values into a +-- PostgreSQL array. +CREATE AGGREGATE array_accum ( + sfunc = array_append, + basetype = anyelement, + stype = anyarray, + initcond = '{}' +); + +-- main table +CREATE TABLE sfa ( + record_id serial PRIMARY KEY , + hrn text NOT NULL, + authority text NOT NULL, + peer_authority text, + gid text, + type text NOT NULL, + pointer integer, + date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP +); +CREATE INDEX sfa_hrn_ids on sfa (hrn); +CREATE INDEX sfa_type_ids on sfa (type); +CREATE INDEX sfa_authority_ids on sfa (authority); +CREATE INDEX sfa_peer_authority_ids on sfa (peer_authority); +CREATE INDEX sfa_pointer_ids on sfa (pointer); diff --git a/sfa/storage/table.py b/sfa/storage/table.py index 3c69fda3..3e47f3e9 100644 --- a/sfa/storage/table.py +++ b/sfa/storage/table.py @@ -56,34 +56,34 @@ class SfaTable(list): def create(self): - - querystr = "CREATE TABLE " + self.tablename + " ( \ - record_id serial PRIMARY KEY , \ - hrn text NOT NULL, \ - authority text NOT NULL, \ - peer_authority text, \ - gid text, \ - type text NOT NULL, \ - pointer integer, \ - date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, \ - last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP);" - template = "CREATE INDEX %s_%s_idx ON %s (%s);" - indexes = [template % ( self.tablename, field, self.tablename, field) \ - for field in ['hrn', 'type', 'authority', 'peer_authority', 'pointer']] - # IF EXISTS doenst exist in postgres < 8.2 - try: - self.db.do('DROP TABLE IF EXISTS ' + self.tablename) - except: - try: - self.db.do('DROP TABLE' + self.tablename) - except: - pass - - self.db.do(querystr) - for index in indexes: - self.db.do(index) - - self.db.commit() + pass +# querystr = "CREATE TABLE " + self.tablename + " ( \ +# record_id serial PRIMARY KEY , \ +# hrn text NOT NULL, \ +# authority text NOT NULL, \ +# peer_authority text, \ +# gid text, \ +# type text NOT NULL, \ +# pointer integer, \ +# date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, \ +# last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP);" +# template = "CREATE INDEX %s_%s_idx ON %s (%s);" +# indexes = [template % ( self.tablename, field, self.tablename, field) \ +# for field in ['hrn', 'type', 'authority', 'peer_authority', 'pointer']] +# # IF EXISTS doenst exist in postgres < 8.2 +# try: +# self.db.do('DROP TABLE IF EXISTS ' + self.tablename) +# except: +# try: +# self.db.do('DROP TABLE' + self.tablename) +# except: +# pass +# +# self.db.do(querystr) +# for index in indexes: +# self.db.do(index) +# +# self.db.commit() def remove(self, record): params = {'record_id': record['record_id']}