{"id":27439216,"url":"https://github.com/hardcode3/expensetracker","last_synced_at":"2025-04-14T21:51:40.749Z","repository":{"id":285148421,"uuid":"957033421","full_name":"Hardcode3/ExpenseTracker","owner":"Hardcode3","description":"Simple backend expense tracker (personal experiment)","archived":false,"fork":false,"pushed_at":"2025-03-29T20:10:03.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T21:22:12.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hardcode3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-29T11:49:42.000Z","updated_at":"2025-03-29T20:10:06.000Z","dependencies_parsed_at":"2025-03-29T21:22:16.506Z","dependency_job_id":"da830d69-79e1-40a9-a600-0456117c534d","html_url":"https://github.com/Hardcode3/ExpenseTracker","commit_stats":null,"previous_names":["hardcode3/expensetracker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hardcode3%2FExpenseTracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hardcode3%2FExpenseTracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hardcode3%2FExpenseTracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hardcode3%2FExpenseTracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hardcode3","download_url":"https://codeload.github.com/Hardcode3/ExpenseTracker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968741,"owners_count":21191158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-14T21:51:40.154Z","updated_at":"2025-04-14T21:51:40.731Z","avatar_url":"https://github.com/Hardcode3.png","language":"Python","readme":"# ExpenseTracker\n\nSimple backend expense tracker (personal experiment)\n\n## Contributing\n\n### Configure environment variables\n\nIn order to run properly and run safe, the code needs multiple environment variables.\n\nA `.env` file must be created at the root of the project to load secrets to memory.\n\nHere is an exhaustive list of variables that must be defined:\n\n- DB_HOST (db, docker-compose container name)\n- DB_PORT (often 5432 for postgres)\n- DB_USER\n- DB_PASSWORD\n- DB_NAME: expense_db\n\nThese environment variables are used:\n\n- to define alembic `sqlalchemy.url` privately\n- to define sql engine in `app.core.database`: `engine = create_engine(DATABASE_URL)`\n\n\u003e [!CAUTION]\n\u003e Do not version your `.env` file.\n\n## Common Debug\n\n### Check that your host machine has access to the api hosted in a container\n\nOutside Docker (on your host machine): The correct way to access the service is:\n\n- `http://localhost:8000`\n- `http://127.0.0.1:8000`\n\n```shell\ncurl -v http://localhost:8000/docs\n```\n\n### Check that your container has access to the the api hosted locally\n\nInside Docker: FastAPI binds to `0.0.0.0`, allowing access from anywhere inside the container.\n\n```shell\ndocker exec -it fastapi_expense_backend sh\n```\n\nthen in the opened container shell:\n\n```shell\ncurl -v http://0.0.0.0:8000/docs\n```\n\n### Check that alembic is up\n\n```shell\ndocker exec -it fastapi_expense_backend alembic current\n```\n\n### Migrating changes made to the database\n\n#### Important notes about containers\n\nIf your Alembic setup is running inside a container (e.g., a Docker container), you can still check the Alembic state by executing commands inside the container:\n\n```shell\ndocker exec -it fastapi_expense_backend sh\n```\n\n\u003e [!CAUTION]\n\u003e Trying to execute alembic from the host machine instead of inside the container will result in an error:\n\u003e `sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name \"db\" to address: Name or service not known`\n\u003e\n\u003e This error is due to the fact that db is the name of the docker-compose service and also the host name.\n\u003e What would work is: \"localhost\" instead of \"db\", however the backend container would not be able to connect to the database url.\n\n\n#### Generate a migration script\n\nAfter making changes to your database models (schemas), you need to generate a migration script.\n\n```shell\nalembic revision --autogenerate -m \"Changed expense to transaction table name\"\n\nINFO  [alembic.runtime.migration] Context impl PostgresqlImpl.\nINFO  [alembic.runtime.migration] Will assume transactional DDL.\nINFO  [alembic.autogenerate.compare] Detected removed index 'ix_transactions_id' on 'transactions'\nINFO  [alembic.autogenerate.compare] Detected removed table 'transactions'\nINFO  [alembic.ddl.postgresql] Detected sequence named 'expenses_id_seq' as owned by integer column 'expenses(id)', assuming SERIAL and omitting\nINFO  [alembic.autogenerate.compare] Detected removed index 'ix_expenses_description' on 'expenses'\nINFO  [alembic.autogenerate.compare] Detected removed index 'ix_expenses_id' on 'expenses'\nINFO  [alembic.autogenerate.compare] Detected removed table 'expenses'\n  Generating /app/alembic/versions/08290ef9350a_changed_expense_to_transaction_table_.py ...  done\n```\n\n- The --autogenerate flag will automatically compare your models with the current database schema and generate the necessary migration.\n- The `-m` flag allows you to provide a message describing the migration (e.g., \"Changed expense to transaction table name\").\n\nAlembic will generate a migration script in the `alembic/versions/` folder. Review the generated script to ensure it properly represents your intended changes.\n\nFor example, if you added a new field to your Transaction model, you should see something like this in the migration script:\n\n```python\ndef upgrade():\n    op.add_column('transactions', sa.Column('new_field', sa.String(), nullable=True))\n\ndef downgrade():\n    op.drop_column('transactions', 'new_field')\n\n```\n\n#### Apply the migration script to the database\n\nTo apply the migration to your database, run the following command:\n\n```shell\nalembic upgrade head\n\nINFO  [alembic.runtime.migration] Context impl PostgresqlImpl.\nINFO  [alembic.runtime.migration] Will assume transactional DDL.\nINFO  [alembic.runtime.migration] Running upgrade 65dd6b98e39b -\u003e 08290ef9350a, Changed expense to transaction table name\n```\n\nAfter running the migration, you can verify the changes in your database by inspecting the tables or running queries.\n\n#### Rollback if needed\n\nRollback the migration: If something goes wrong, you can downgrade to a previous revision:\n\n```shell\nalembic downgrade -1  # Go back 1 revision\n```\n\n#### Check the current version of the database schema\n\nCheck the current version: To see the current state of the database schema:\n\n```shell\nalembic current\n\nINFO  [alembic.runtime.migration] Context impl PostgresqlImpl.\nINFO  [alembic.runtime.migration] Will assume transactional DDL.\n08290ef9350a (head)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardcode3%2Fexpensetracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardcode3%2Fexpensetracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardcode3%2Fexpensetracker/lists"}