diff --git a/ingredients_db/alembic/versions/1fdbfd6b0eea_create_instance.py b/ingredients_db/alembic/versions/1fdbfd6b0eea_create_instance.py index 4de2dee..22752e0 100644 --- a/ingredients_db/alembic/versions/1fdbfd6b0eea_create_instance.py +++ b/ingredients_db/alembic/versions/1fdbfd6b0eea_create_instance.py @@ -31,8 +31,10 @@ def upgrade(): sa.Column('project_id', sau.UUIDType, sa.ForeignKey('projects.id', ondelete='RESTRICT'), nullable=False), sa.Column('current_task_id', sau.UUIDType, sa.ForeignKey('tasks.id')), sa.Column('image_id', sau.UUIDType, sa.ForeignKey('images.id', ondelete='SET NULL')), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), ) diff --git a/ingredients_db/alembic/versions/3ce1572cbc6b_create_tasks.py b/ingredients_db/alembic/versions/3ce1572cbc6b_create_tasks.py index 2331889..5bebf9b 100644 --- a/ingredients_db/alembic/versions/3ce1572cbc6b_create_tasks.py +++ b/ingredients_db/alembic/versions/3ce1572cbc6b_create_tasks.py @@ -26,8 +26,10 @@ def upgrade(): sa.Column('state', sa.Enum(TaskState), default=TaskState.PENDING, nullable=False), sa.Column('error_message', sa.Text), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), sa.Column('stopped_at', sau.ArrowType(timezone=True)), ) diff --git a/ingredients_db/alembic/versions/458762cd0419_create_authn_user.py b/ingredients_db/alembic/versions/458762cd0419_create_authn_user.py index f718df7..6dfe591 100644 --- a/ingredients_db/alembic/versions/458762cd0419_create_authn_user.py +++ b/ingredients_db/alembic/versions/458762cd0419_create_authn_user.py @@ -22,8 +22,10 @@ def upgrade(): sa.Column('id', sau.UUIDType, server_default=sa.text("uuid_generate_v4()"), primary_key=True), sa.Column('username', sa.String, nullable=False), sa.Column('driver', sa.String, nullable=False), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) op.create_unique_constraint('uq_username_driver', 'authn_users', ['username', 'driver']) diff --git a/ingredients_db/alembic/versions/52923fe51ede_create_image.py b/ingredients_db/alembic/versions/52923fe51ede_create_image.py index db10dbf..aa0b1c7 100644 --- a/ingredients_db/alembic/versions/52923fe51ede_create_image.py +++ b/ingredients_db/alembic/versions/52923fe51ede_create_image.py @@ -33,8 +33,10 @@ def upgrade(): sa.Column('project_id', sau.UUIDType, sa.ForeignKey('projects.id', ondelete='RESTRICT'), nullable=False), sa.Column('current_task_id', sau.UUIDType, sa.ForeignKey('tasks.id')), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), ) @@ -45,7 +47,8 @@ def upgrade(): sa.Column('project_id', sau.UUIDType, sa.ForeignKey('projects.id', ondelete='CASCADE'), nullable=False, primary_key=True), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), ) diff --git a/ingredients_db/alembic/versions/9d6460001e00_create_network.py b/ingredients_db/alembic/versions/9d6460001e00_create_network.py index 9a4a9b0..ccf4bb9 100644 --- a/ingredients_db/alembic/versions/9d6460001e00_create_network.py +++ b/ingredients_db/alembic/versions/9d6460001e00_create_network.py @@ -33,8 +33,10 @@ def upgrade(): sa.Column('cidr', IPv4Network, nullable=False), sa.Column('pool_start', sau.IPAddressType, nullable=False), sa.Column('pool_end', sau.IPAddressType, nullable=False), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), ) diff --git a/ingredients_db/alembic/versions/b129792f908b_create_network_port.py b/ingredients_db/alembic/versions/b129792f908b_create_network_port.py index 3443b79..6761050 100644 --- a/ingredients_db/alembic/versions/b129792f908b_create_network_port.py +++ b/ingredients_db/alembic/versions/b129792f908b_create_network_port.py @@ -24,8 +24,10 @@ def upgrade(): sa.Column('network_id', sau.UUIDType, sa.ForeignKey('networks.id', ondelete='RESTRICT'), nullable=False), sa.Column('ip_address', sau.IPAddressType), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) diff --git a/ingredients_db/alembic/versions/ba0652dfa1be_create_public_keys.py b/ingredients_db/alembic/versions/ba0652dfa1be_create_public_keys.py index 131859a..d6b565c 100644 --- a/ingredients_db/alembic/versions/ba0652dfa1be_create_public_keys.py +++ b/ingredients_db/alembic/versions/ba0652dfa1be_create_public_keys.py @@ -25,8 +25,10 @@ def upgrade(): sa.Column('project_id', sau.UUIDType, sa.ForeignKey('projects.id', ondelete='CASCADE'), nullable=False), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) @@ -37,8 +39,10 @@ def upgrade(): sa.Column('public_key_id', sau.UUIDType, sa.ForeignKey('public_keys.id', ondelete='CASCADE')), sa.Column('instance_id', sau.UUIDType, sa.ForeignKey('instances.id', ondelete='CASCADE')), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) diff --git a/ingredients_db/alembic/versions/dadf4ada480a_create_authz.py b/ingredients_db/alembic/versions/dadf4ada480a_create_authz.py index 25a40f8..6375b60 100644 --- a/ingredients_db/alembic/versions/dadf4ada480a_create_authz.py +++ b/ingredients_db/alembic/versions/dadf4ada480a_create_authz.py @@ -23,8 +23,10 @@ def upgrade(): sa.Column('name', sa.String, nullable=False, unique=True), sa.Column('rule', sa.String, nullable=False), sa.Column('description', sa.String), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) @@ -33,8 +35,10 @@ def upgrade(): sa.Column('id', sau.UUIDType, server_default=sa.text("uuid_generate_v4()"), primary_key=True), sa.Column('name', sa.String, nullable=False, unique=True), sa.Column('description', sa.String), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) @@ -46,8 +50,10 @@ def upgrade(): sa.Column('user_id', sau.UUIDType, sa.ForeignKey('authn_users.id', ondelete='CASCADE'), nullable=False), sa.Column('project_id', sau.UUIDType, sa.ForeignKey('projects.id', ondelete='CASCADE')), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), sa.Column('expires_at', sau.ArrowType(timezone=True), nullable=False) ) @@ -59,8 +65,10 @@ def upgrade(): sa.Column('token_id', sau.UUIDType, sa.ForeignKey('authn_tokens.id', ondelete='CASCADE'), nullable=False), sa.Column('role_id', sau.UUIDType, sa.ForeignKey('authz_roles.id', ondelete='CASCADE'), nullable=False), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False), ) @@ -132,7 +140,9 @@ def upgrade(): {"name": "instances:action:image:public", "rule": "rule:is_admin", "description": "Ability to create a public image from an instance"}, {"name": "instances:action:reset_state", "rule": "rule:admin_or_member", - "description": "Ability to reset the state of an instance"}, + "description": "Ability to reset the state of an instance to error"}, + {"name": "instances:action:reset_state:active", "rule": "rule:is_admin", + "description": "Ability to reset the state of an instance to active"}, # Networks {"name": "networks:create", "rule": "rule:is_admin", "description": "Ability to create a network"}, diff --git a/ingredients_db/alembic/versions/f422a466b0a8_create_project.py b/ingredients_db/alembic/versions/f422a466b0a8_create_project.py index 2c38e22..c3c7d0c 100644 --- a/ingredients_db/alembic/versions/f422a466b0a8_create_project.py +++ b/ingredients_db/alembic/versions/f422a466b0a8_create_project.py @@ -25,8 +25,10 @@ def upgrade(): sa.Column('name', sa.String, unique=True, nullable=False), sa.Column('state', sa.Enum(ProjectState), default=ProjectState.CREATED, nullable=False), - sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), nullable=False, index=True), - sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.func.now(), onupdate=sa.func.now(), + sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + nullable=False, index=True), + sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), + onupdate=sa.text('clock_timestamp()'), nullable=False) ) diff --git a/ingredients_db/models/authn.py b/ingredients_db/models/authn.py index c08f34a..f23adae 100644 --- a/ingredients_db/models/authn.py +++ b/ingredients_db/models/authn.py @@ -1,5 +1,5 @@ import arrow -from sqlalchemy import func, Column, String, text, ForeignKey, UniqueConstraint +from sqlalchemy import Column, String, text, ForeignKey, UniqueConstraint from sqlalchemy_utils import generic_repr, ArrowType, UUIDType from ingredients_db.database import Base @@ -16,8 +16,9 @@ class AuthNUser(Base): username = Column(String, nullable=False) driver = Column(String, nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) @generic_repr @@ -30,8 +31,9 @@ class AuthNToken(Base): user_id = Column(UUIDType, ForeignKey('authn_users.id', ondelete='CASCADE'), nullable=False) project_id = Column(UUIDType, ForeignKey('projects.id', ondelete='CASCADE')) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) expires_at = Column(ArrowType(timezone=True), default=arrow.now().shift(days=+1), nullable=False) @@ -42,5 +44,6 @@ class AuthNTokenRole(Base): token_id = Column(UUIDType, ForeignKey('authn_tokens.id', ondelete='CASCADE'), nullable=False) role_id = Column(UUIDType, ForeignKey('authz_roles.id', ondelete='CASCADE'), nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) diff --git a/ingredients_db/models/authz.py b/ingredients_db/models/authz.py index 16399d3..aa4e01b 100644 --- a/ingredients_db/models/authz.py +++ b/ingredients_db/models/authz.py @@ -1,4 +1,4 @@ -from sqlalchemy import text, Column, func, String +from sqlalchemy import text, Column, String from sqlalchemy_utils import UUIDType, ArrowType from ingredients_db.database import Base @@ -13,8 +13,9 @@ class AuthZPolicy(Base): rule = Column(String, nullable=False) description = Column(String) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) # TODO: should we have locked roles to prevent accidental deletion? @@ -25,5 +26,6 @@ class AuthZRole(Base): name = Column(String, nullable=False, unique=True) description = Column(String) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) diff --git a/ingredients_db/models/images.py b/ingredients_db/models/images.py index bd385e2..0f691a0 100644 --- a/ingredients_db/models/images.py +++ b/ingredients_db/models/images.py @@ -1,6 +1,6 @@ import enum -from sqlalchemy import Column, func, String, ForeignKey, Enum, Boolean, text +from sqlalchemy import Column, String, ForeignKey, Enum, Boolean, text from sqlalchemy.orm import relationship from sqlalchemy_utils import UUIDType, ArrowType, generic_repr @@ -30,7 +30,7 @@ class ImageMembers(Base): image_id = Column(UUIDType, ForeignKey('images.id', ondelete='CASCADE'), nullable=False, primary_key=True) project_id = Column(UUIDType, ForeignKey('projects.id', ondelete='CASCADE'), nullable=False, primary_key=True) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) # TODO: Image families @@ -47,7 +47,8 @@ class Image(Base, TaskMixin, ProjectMixin): state = Column(Enum(ImageState), default=ImageState.CREATING, nullable=False) visibility = Column(Enum(ImageVisibility), default=ImageVisibility.PRIVATE, nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) members = relationship(Project, secondary='image_members') diff --git a/ingredients_db/models/instance.py b/ingredients_db/models/instance.py index d6dc458..b4e95af 100644 --- a/ingredients_db/models/instance.py +++ b/ingredients_db/models/instance.py @@ -1,6 +1,6 @@ import enum -from sqlalchemy import Column, String, ForeignKey, Enum, text, func +from sqlalchemy import Column, String, ForeignKey, Enum, text from sqlalchemy.dialects.postgresql import HSTORE from sqlalchemy.orm import relationship from sqlalchemy_utils import UUIDType, generic_repr, ArrowType @@ -38,8 +38,9 @@ class Instance(Base, TaskMixin, NetworkableMixin, ProjectMixin): public_keys = relationship(PublicKey, secondary='instance_public_keys') - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) class InstancePublicKey(Base): @@ -50,5 +51,6 @@ class InstancePublicKey(Base): public_key_id = Column(UUIDType, ForeignKey('public_keys.id', ondelete='CASCADE')) instance_id = Column(UUIDType, ForeignKey('instances.id', ondelete='CASCADE')) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) diff --git a/ingredients_db/models/network.py b/ingredients_db/models/network.py index 5b8d584..0519ed5 100644 --- a/ingredients_db/models/network.py +++ b/ingredients_db/models/network.py @@ -2,7 +2,7 @@ import ipaddress from typing import Optional -from sqlalchemy import Column, String, Enum, text, func +from sqlalchemy import Column, String, Enum, text from sqlalchemy_utils import UUIDType, generic_repr, IPAddressType, ArrowType from ingredients_db.database import Base @@ -34,8 +34,9 @@ class Network(Base, TaskMixin): pool_start = Column(IPAddressType, nullable=False) pool_end = Column(IPAddressType, nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) def next_free_address(self, session) -> Optional[ipaddress.IPv4Address]: ip_network = ipaddress.ip_network(self.cidr) diff --git a/ingredients_db/models/network_port.py b/ingredients_db/models/network_port.py index cb6f09d..09f227e 100644 --- a/ingredients_db/models/network_port.py +++ b/ingredients_db/models/network_port.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, text, func, ForeignKey +from sqlalchemy import Column, text, ForeignKey from sqlalchemy.ext.declarative import declared_attr from sqlalchemy_utils import UUIDType, ArrowType, generic_repr, IPAddressType @@ -14,8 +14,9 @@ class NetworkPort(Base): network_id = Column(UUIDType, ForeignKey('networks.id', ondelete='RESTRICT'), nullable=False) ip_address = Column(IPAddressType) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) class NetworkableMixin(object): diff --git a/ingredients_db/models/project.py b/ingredients_db/models/project.py index aca9079..f79466d 100644 --- a/ingredients_db/models/project.py +++ b/ingredients_db/models/project.py @@ -1,6 +1,6 @@ import enum -from sqlalchemy import Column, text, func, String, Enum, ForeignKey +from sqlalchemy import Column, text, String, Enum, ForeignKey from sqlalchemy.ext.declarative import declared_attr from sqlalchemy_utils import UUIDType, ArrowType, generic_repr @@ -26,8 +26,9 @@ class Project(Base): name = Column(String, unique=True, nullable=False) state = Column(Enum(ProjectState), default=ProjectState.CREATED, nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) class ProjectMixin(object): diff --git a/ingredients_db/models/public_key.py b/ingredients_db/models/public_key.py index f9b28f1..8e9b6b6 100644 --- a/ingredients_db/models/public_key.py +++ b/ingredients_db/models/public_key.py @@ -1,4 +1,4 @@ -from sqlalchemy import text, Column, String, Text, func, ForeignKey +from sqlalchemy import text, Column, String, Text, ForeignKey from sqlalchemy_utils import UUIDType, generic_repr, ArrowType from ingredients_db.database import Base @@ -14,5 +14,6 @@ class PublicKey(Base): project_id = Column(UUIDType, ForeignKey('projects.id', ondelete='CASCADE'), nullable=False) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) diff --git a/ingredients_db/models/task.py b/ingredients_db/models/task.py index a607e6e..8c41d62 100644 --- a/ingredients_db/models/task.py +++ b/ingredients_db/models/task.py @@ -1,6 +1,6 @@ import enum -from sqlalchemy import text, Column, String, Enum, Text, func, ForeignKey +from sqlalchemy import text, Column, String, Enum, Text, ForeignKey from sqlalchemy.ext.declarative import declared_attr from sqlalchemy_utils import UUIDType, ArrowType, generic_repr @@ -23,8 +23,9 @@ class Task(Base): state = Column(Enum(TaskState), default=TaskState.PENDING, nullable=False) error_message = Column(Text) - created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) - updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) + created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False) + updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), + onupdate=text('clock_timestamp()'), nullable=False) stopped_at = Column(ArrowType(timezone=True)) diff --git a/ingredients_db/models/user.py b/ingredients_db/models/user.py deleted file mode 100644 index f2b77d7..0000000 --- a/ingredients_db/models/user.py +++ /dev/null @@ -1,31 +0,0 @@ -# import arrow -# from sqlalchemy import Column, text, func, String, ForeignKey -# from sqlalchemy_utils import UUIDType, ArrowType, generic_repr -# -# from ingredients_db.database import Base - - -# @generic_repr -# class User(Base): -# __tablename__ = 'users' -# -# id = Column(UUIDType, server_default=text("uuid_generate_v4()"), primary_key=True) -# username = Column(String, unique=True, nullable=False) -# -# created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False) -# updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) -# -# -# @generic_repr -# class UserToken(Base): -# __tablename__ = 'user_tokens' -# -# id = Column(UUIDType, server_default=text("uuid_generate_v4()"), primary_key=True) -# access_token = Column(String, nullable=False, index=True) -# -# user_id = Column(UUIDType, ForeignKey('users.id', ondelete='CASCADE'), nullable=False) -# project_id = Column(UUIDType, ForeignKey('projects.id', ondelete='CASCADE')) -# -# created_at = Column(ArrowType(timezone=True), server_default=func.now(), nullable=False, index=True) -# updated_at = Column(ArrowType(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False) -# expires_at = Column(ArrowType(timezone=True), default=arrow.now().shift(days=+1), nullable=False)