From 1f7f74d59e2ce21cc31bb062f1520107a7235ee9 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Mon, 19 Aug 2019 18:12:56 +0000 Subject: [PATCH] Merge branch 'noc-last-login-nullable' into 'master' Ensure User.last_login is nullable See merge request noc/noc!2503 (cherry picked from commit 4fce734a4a852afea9901b01b011e178cdee11e4) 6ce8bf0b Ensure User.last_login is nullable 010e06d3 PEP8 --- aaa/migrations/0008_user_last_login_null.py | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 aaa/migrations/0008_user_last_login_null.py diff --git a/aaa/migrations/0008_user_last_login_null.py b/aaa/migrations/0008_user_last_login_null.py new file mode 100644 index 0000000000..31e4d895ba --- /dev/null +++ b/aaa/migrations/0008_user_last_login_null.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# ---------------------------------------------------------------------- +# Set auth_user.last_login to NULLable +# ---------------------------------------------------------------------- +# Copyright (C) 2007-2019 The NOC Project +# See LICENSE for details +# ---------------------------------------------------------------------- + +# NOC modules +from noc.core.migration.base import BaseMigration + + +class Migration(BaseMigration): + def migrate(self): + is_nullable = self.db.execute( + """ + SELECT is_nullable = 'YES' + FROM information_schema.columns + WHERE + table_name = 'auth_user' + AND column_name = 'last_login' + """ + )[0][0] + if is_nullable: + return + self.db.execute( + """ + ALTER TABLE auth_user + ALTER last_login + DROP NOT NULL + """ + ) -- GitLab