Skip to content

Commit

Permalink
added migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Nov 13, 2019
1 parent 0b57c5e commit 2002075
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions piccolo_api/session_auth/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ async def post(self, request: Request) -> RedirectResponse:


def session_login(
auth_table: BaseUser,
session_table: SessionsBase,
auth_table: BaseUser = BaseUser,
session_table: SessionsBase = SessionsBase,
expiry: timedelta = timedelta(hours=1),
redirect_to: str = "/",
production: bool = False,
Expand All @@ -139,7 +139,7 @@ class _SessionLoginEndpoint(SessionLoginEndpoint):


def session_logout(
session_table: SessionsBase,
session_table: SessionsBase = SessionsBase,
) -> t.Type[SessionLogoutEndpoint]:
class _SessionLogoutEndpoint(SessionLogoutEndpoint):
_session_table = session_table
Expand Down
20 changes: 20 additions & 0 deletions piccolo_api/session_auth/migrations/2019-11-12T20:47:17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from piccolo.table import Table
from piccolo.columns import Varchar, Integer, Timestamp


ID = "2019-11-12T20:47:17"


class SessionsBase(Table, tablename="sessions"):
token = Varchar(length=100, null=False)
user_id = Integer(null=False)
expiry_date = Timestamp(null=False)
max_expiry_date = Timestamp(null=False)


async def forwards():
await SessionsBase.create().run()


async def backwards():
await SessionsBase.alter().drop_table().run()
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion piccolo_api/session_auth/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def max_expiry_date() -> datetime:
return datetime.now() + timedelta(days=7)


class SessionsBase(Table):
class SessionsBase(Table, tablename="sessions"):
"""
Inherit from this table for a session store.
"""
Expand Down

0 comments on commit 2002075

Please sign in to comment.