DoSomething / bertly

🔗 A serverless link shortener.
https://dosome.click/wq544
MIT License
2 stars 1 forks source link

Clicks postgres #17

Closed mshmsh5000 closed 6 years ago

mshmsh5000 commented 6 years ago

What's this PR do?

This PR provides the Serverless integration pieces that map a custom domain to the app.

How should this be reviewed?

Running locally, you can invoke the server with Postgres connection credentials:

POSTGRESQL_USER="myuser" POSTGRESQL_DB="bertly_clicks" POSTGRESQL_HOST="localhost" POSTGRESQL_PORT="5432" CLICK_TABLE="clicks" COMPOSE_REDIS_URL="redis://user:pass@redisserver.com:12345" BERTLY_API_KEY_NAME="X-BERTLY-API-KEY" BERTLY_API_KEY="testing" sls  wsgi serve

You'll need to run the migration command to create the table: python manage.py db upgrade

This creates the clicks table.

When you make a request to a shortened URL, you should see entries in clicks:

bertly_clicks=# SELECT * FROM clicks;
     click_id     |         click_time         | shortened |            target_url
------------------+----------------------------+-----------+----------------------------------
 3Fu1525487501.41 | 2018-05-05 02:31:41.405265 | 3Fu       | https://www.nytimes.com/
 3Fu1525487608.36 | 2018-05-05 02:33:28.35897  | 3Fu       | https://www.nytimes.com/
 3Fu1525487608.38 | 2018-05-05 02:33:28.378791 | 3Fu       | https://www.nytimes.com/

Any background context you want to provide?

This uses SQLAlchemy as the ORM, and Alembic for migrations. There's only one migration.

Relevant tickets

16

Checklist