Index: /branches/amp_3_7_1/scripts/avxapps_startup.sh
===================================================================
--- /branches/amp_3_7_1/scripts/avxapps_startup.sh	(revision 2410)
+++ /branches/amp_3_7_1/scripts/avxapps_startup.sh	(working copy)
@@ -70,6 +70,7 @@
     # /usr/bin/python /ca/webui/htdocs/new/src/clean_elastic.py crontab
     # /usr/bin/python /ca/bin/clean_oper_log.py crontab
     /usr/bin/python /ca/webui/htdocs/new/src/cm/lib/postgres_db.py
+    /usr/bin/python /ca/webui/htdocs/new/src/cm/upgrade/update_postgres_3_7_1.py
     rm -rf /var/run/webui_server.pem
 
     sed -i -e 's|SELINUX=enforcing|SELINUX=disabled|' /etc/selinux/config
Index: /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py
===================================================================
--- /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py	(revision 2410)
+++ /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/lib/postgres_db.py	(working copy)
@@ -243,7 +243,8 @@
         CREATE TABLE IF NOT EXISTS device_group (
             name character varying(128) COLLATE pg_catalog."default" NOT NULL,
             CONSTRAINT device_group_pkey PRIMARY KEY (name)
-        )'''
+        );
+        ALTER TABLE device_group ADD COLUMN IF NOT EXISTS id SERIAL;'''
         self.execute_sql(create_table_sql)
 
     def create_table_ha_cluster(self):
@@ -421,7 +422,6 @@
                               result varchar(20) NOT NULL
                             );
                             ALTER TABLE ext_log ADD COLUMN IF NOT EXISTS id BIGSERIAL;
-                            ALTER TABLE ext_log DROP CONSTRAINT ext_log_pkey;
                             ALTER TABLE ext_log ADD CONSTRAINT ext_log_pkey PRIMARY KEY (id);
                             '''
         self.execute_sql(create_table_sql)
@@ -507,7 +507,12 @@
             created_at timestamp without time zone,
             FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE CASCADE,
             FOREIGN KEY (device_group_name) REFERENCES device_group(name) ON DELETE CASCADE
-        );'''
+        );
+        ALTER TABLE role_device_group DROP CONSTRAINT IF EXISTS role_device_group_device_group_name_fkey;
+        ALTER TABLE device_group DROP CONSTRAINT IF EXISTS device_group_pkey CASCADE;
+        ALTER TABLE device_group ADD CONSTRAINT device_group_id_pkey PRIMARY KEY (id);
+        ALTER TABLE role_device_group ADD COLUMN IF NOT EXISTS device_group_id int;
+        ALTER TABLE role_device_group ADD CONSTRAINT role_dev_grp_name_fkey FOREIGN KEY(device_group_id) REFERENCES device_group(id) ON DELETE CASCADE;'''
         self.execute_sql(create_table_query)
 
 
Index: /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/__init__.py
===================================================================
--- /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/__init__.py	(revision 0)
+++ /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/__init__.py	(working copy)
@@ -0,0 +1 @@
+__all__ = ["update_postgres_3_7_1"]
\ No newline at end of file
Index: /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/update_postgres_3_7_1.py
===================================================================
--- /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/update_postgres_3_7_1.py	(revision 0)
+++ /branches/amp_3_7_1/src/webui/webui/htdocs/new/src/cm/upgrade/update_postgres_3_7_1.py	(working copy)
@@ -0,0 +1,55 @@
+import sys
+import os
+
+# Get the current file's directory
+current_dir = os.path.dirname(os.path.abspath(__file__))
+
+# Move two levels up
+one_level_up = os.path.abspath(os.path.join(current_dir, "../"))
+
+# Add the directory to sys.path
+sys.path.append(one_level_up)
+
+# Now you can import the module
+from lib.postgres_db import DB
+
+
+def update_device_group_id():
+    db = DB.get_connected_db()
+    update_device_id_sql = '''
+    WITH device_group_cte AS (
+        SELECT name, id
+        FROM device_group
+    )
+    UPDATE role_device_group
+    SET device_group_id = device_group_cte.id
+    FROM device_group_cte
+    WHERE role_device_group.device_group_name = device_group_cte.name
+      AND role_device_group.device_group_id IS NULL;
+    '''
+
+    db.execute_sql(update_device_id_sql)
+    db.close()
+
+
+def update_file_type():
+    db = DB.get_connected_db()
+    update_file_type_sql = '''
+    WITH file_type_cte AS (
+        SELECT name, id
+        FROM file_type
+    )
+    UPDATE file_list
+    SET file_type_id = file_type_cte.id
+    FROM file_type_cte
+    WHERE file_list.file_type_name = file_type_cte.name
+      AND file_list.file_type_id IS NULL;
+    '''
+
+    db.execute_sql(update_file_type_sql)
+    db.close()
+
+
+if __name__ == '__main__':
+    update_device_group_id()
+    update_file_type()
\ No newline at end of file
