ship database schema in a separate file
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 29 Nov 2011 14:29:58 +0000 (15:29 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 29 Nov 2011 14:29:58 +0000 (15:29 +0100)
init.d/sfa
setup.py
sfa.spec
sfa/storage/sfa.sql [new file with mode: 0644]
sfa/storage/table.py

index 92c70ea..a3cd544 100755 (executable)
@@ -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
 
index c0a8b9e..9f68e18 100755 (executable)
--- 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)]
index 9fd9cc9..a96d177 100644 (file)
--- 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 (file)
index 0000000..3d7984d
--- /dev/null
@@ -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);
index 3c69fda..3e47f3e 100644 (file)
@@ -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']}