Skip to content

Commit

Permalink
#134 - db schema update
Browse files Browse the repository at this point in the history
  • Loading branch information
grindsa committed Feb 19, 2024
1 parent bdb1ddc commit 3f24611
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion acme_srv/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module module
__version__ = '0.33.1'
__dbversion__ = '0.33'
__dbversion__ = '0.33.2'
15 changes: 13 additions & 2 deletions examples/db_handler/wsgi_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _db_create(self):
CREATE TABLE "certificate" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(15) NOT NULL UNIQUE, "cert" text, "cert_raw" text, "error" text, "order_id" integer NOT NULL REFERENCES "order" ("id"), "csr" text NOT NULL, "poll_identifier" text, "header_info" text, "created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, "renewal_info" text, "aki" text, "serial" text, "issue_uts" integer DEFAULT 0, "expire_uts" integer DEFAULT 0, "replaced" bolean DEFAULT 0)
''')
self.cursor.execute('''
CREATE TABLE "housekeeping" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(15) NOT NULL UNIQUE, "value" text, "modified_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)
CREATE TABLE "housekeeping" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL UNIQUE, "value" text, "modified_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)
''')
self.cursor.execute('''
CREATE TRIGGER [UpdateLastTime]
Expand Down Expand Up @@ -421,7 +421,7 @@ def _db_update_housekeeping(self):
if self.cursor.fetchone()[0] != 1:
self.logger.info('create housekeeping table and trigger')
self.cursor.execute('''
CREATE TABLE "housekeeping" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(15) NOT NULL UNIQUE, "value" text, "modified_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)
CREATE TABLE "housekeeping" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL UNIQUE, "value" text, "modified_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)
''')
self.cursor.execute('''
CREATE TRIGGER [UpdateLastTime]
Expand All @@ -434,6 +434,17 @@ def _db_update_housekeeping(self):
update housekeeping set modified_at=CURRENT_TIMESTAMP where id=OLD.id;
END
''')
else:
self.cursor.execute('''PRAGMA table_info(housekeeping)''')
for column in self.cursor.fetchall():
if column[1] == 'name' and column[2].lower() == 'varchar(15)':
self.logger.info('alter housekeeping table - change size of the name field to 30')
self.cursor.execute('''ALTER TABLE housekeeping RENAME TO tmp_hk''')
self.cursor.execute('''
CREATE TABLE "housekeeping" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL UNIQUE, "value" text, "modified_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL)
''')
self.cursor.execute('''INSERT INTO housekeeping(id, name, value, modified_at) SELECT id, name, value, modified_at FROM tmp_hk''')
self.cursor.execute('''DROP TABLE tmp_hk''')

def _db_update_orders(self):
""" alter orders table """
Expand Down
2 changes: 1 addition & 1 deletion examples/django/acme_srv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __unicode__(self):

class Housekeeping(models.Model):
""" housekeeping """
name = models.CharField(max_length=15, unique=True)
name = models.CharField(max_length=30, unique=True)
value = models.CharField(max_length=30, blank=True)
modified_at = models.DateTimeField('value', auto_now_add=True, null=True)

Expand Down

0 comments on commit 3f24611

Please sign in to comment.