update_tables_0.3.x-0.4.py
changeset 20 55146c78b3fb
parent 15 1607f7b2dba9
--- a/update_tables_0.3.x-0.4.py	Fri Apr 18 03:46:11 2008 +0000
+++ b/update_tables_0.3.x-0.4.py	Mon Apr 21 04:56:01 2008 +0000
@@ -70,6 +70,10 @@
 dbh.commit()
 dbc.execute("ALTER TABLE users ADD tid bigint NOT NULL DEFAULT 1")
 dbh.commit()
+for service in ['smtp', 'pop3', 'imap', 'managesieve']:
+    dbc.execute(
+            "ALTER TABLE users ADD %s boolean NOT NULL DEFAULT TRUE" % service)
+    dbh.commit()
 dbc.execute("ALTER TABLE users ADD CONSTRAINT fkey_users_mid_maillocation \
  FOREIGN KEY (mid) REFERENCES maillocation (mid)")
 dbh.commit()
@@ -92,6 +96,14 @@
                 maillocation)
     dbh.commit()
 
+dbc.execute("SELECT uid FROM users WHERE disabled")
+res = dbc.fetchall()
+if len(res):
+    for uid in res:
+        dbc.execute("UPDATE users SET smtp = FALSE, pop3 = FALSE, imap = FALSE,\
+ managesieve = FALSE WHERE uid = %s", uid[0])
+    dbh.commit()
+
 dbc.execute("SELECT gid, tid FROM domains")
 res = dbc.fetchall()
 for gid, tid in res:
@@ -120,11 +132,23 @@
            LEFT JOIN maillocation USING (mid);""")
 dbh.commit()
 
+# Replace VIEW dovecot_password
+dbc.execute("DROP VIEW dovecot_password")
+dbh.commit()
+dbc.execute("""CREATE OR REPLACE VIEW dovecot_password AS
+    SELECT local_part || '@' || domains.domainname AS "user",
+           passwd AS "password", smtp, pop3, imap, managesieve
+      FROM users
+           LEFT JOIN domains USING (gid)""")
+dbh.commit()
+
 # fix table users (Part II)
 dbc.execute("ALTER TABLE users DROP home")
 dbh.commit()
 dbc.execute("ALTER TABLE users DROP mail")
 dbh.commit()
+dbc.execute("ALTER TABLE users DROP disabled")
+dbh.commit()
 
 
 # Replace VIEW postfix_transport