
from neutron_lib.db import model_base
import sqlalchemy as sa


class DFLockedObjects(model_base.BASEV2):
    __tablename__ = 'dflockedobjects'

    object_uuid = sa.Column(sa.String(36), primary_key=True)
    lock = sa.Column(sa.Boolean, default=False)
    session_id = sa.Column(sa.BigInteger, default=0)
    created_at = sa.Column(sa.DateTime, onupdate=sa.func.utc_timestamp())


from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import expression
from sqlalchemy import types


class utc_timestamp(expression.FunctionElement):
    type = types.DateTime()


@compiles(utc_timestamp, 'postgresql')
def pg_utc_timestamp(element, compiler, **kw):
    return "TIMEZONE('utc', CURRENT_TIMESTAMP)"


@compiles(utc_timestamp, 'mssql')
def ms_utc_timestamp(element, compiler, **kw):
    return "GETUTCDATE()"


@compiles(utc_timestamp, 'mysql')
def my_utc_timestamp(element, compiler, **kw):
    return "UTC_TIMESTAMP()"


class DFLockedObjects(model_base.BASEV2):
    __tablename__ = 'dflockedobjects'

    object_uuid = sa.Column(sa.String(36), primary_key=True)
    lock = sa.Column(sa.Boolean, default=False)
    session_id = sa.Column(sa.BigInteger, default=0)
    created_at = sa.Column(sa.DateTime, onupdate=utc_timestamp())

Implement utc_timeout for PGSQL and MSSQL
Implement utc_timeout for PGSQL and MSSQL

UTC_TIMESTAMP is a MySQL specific function. Use SQLAlchemy to implement it
also in MSSQL and PGSQL.

Change-Id: If8673b543da2a89a2bad87daff2429cb09c735aa
Closes-Bug: #1700873

  
  from neutron_lib.db import model_base
  import sqlalchemy as sa
+ from sqlalchemy.ext.compiler import compiles
+ from sqlalchemy.sql import expression
+ from sqlalchemy import types
+ 
+ 
+ class utc_timestamp(expression.FunctionElement):
+     type = types.DateTime()
+ 
+ 
+ @compiles(utc_timestamp, 'postgresql')
+ def pg_utc_timestamp(element, compiler, **kw):
+     return "TIMEZONE('utc', CURRENT_TIMESTAMP)"
+ 
+ 
+ @compiles(utc_timestamp, 'mssql')
+ def ms_utc_timestamp(element, compiler, **kw):
+     return "GETUTCDATE()"
+ 
+ 
+ @compiles(utc_timestamp, 'mysql')
+ def my_utc_timestamp(element, compiler, **kw):
+     return "UTC_TIMESTAMP()"
  
  
  class DFLockedObjects(model_base.BASEV2):
      __tablename__ = 'dflockedobjects'
  
      object_uuid = sa.Column(sa.String(36), primary_key=True)
      lock = sa.Column(sa.Boolean, default=False)
      session_id = sa.Column(sa.BigInteger, default=0)
-     created_at = sa.Column(sa.DateTime, onupdate=sa.func.utc_timestamp())
+     created_at = sa.Column(sa.DateTime, onupdate=utc_timestamp())
  
Implement utc_timeout for PGSQL and MSSQL
## Code Before:

from neutron_lib.db import model_base
import sqlalchemy as sa


class DFLockedObjects(model_base.BASEV2):
    __tablename__ = 'dflockedobjects'

    object_uuid = sa.Column(sa.String(36), primary_key=True)
    lock = sa.Column(sa.Boolean, default=False)
    session_id = sa.Column(sa.BigInteger, default=0)
    created_at = sa.Column(sa.DateTime, onupdate=sa.func.utc_timestamp())

## Instruction:
Implement utc_timeout for PGSQL and MSSQL
## Code After:

from neutron_lib.db import model_base
import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import expression
from sqlalchemy import types


class utc_timestamp(expression.FunctionElement):
    type = types.DateTime()


@compiles(utc_timestamp, 'postgresql')
def pg_utc_timestamp(element, compiler, **kw):
    return "TIMEZONE('utc', CURRENT_TIMESTAMP)"


@compiles(utc_timestamp, 'mssql')
def ms_utc_timestamp(element, compiler, **kw):
    return "GETUTCDATE()"


@compiles(utc_timestamp, 'mysql')
def my_utc_timestamp(element, compiler, **kw):
    return "UTC_TIMESTAMP()"


class DFLockedObjects(model_base.BASEV2):
    __tablename__ = 'dflockedobjects'

    object_uuid = sa.Column(sa.String(36), primary_key=True)
    lock = sa.Column(sa.Boolean, default=False)
    session_id = sa.Column(sa.BigInteger, default=0)
    created_at = sa.Column(sa.DateTime, onupdate=utc_timestamp())
