44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
# Copyright (C) 2026 Dcntrlized
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
Example seed for the shared dcntrlized database.
|
|
|
|
Seeds run automatically after migrations complete, via the compose 'seed'
|
|
service: database/seeds is mounted read-only into a python container and every
|
|
*.py file here is executed in sorted order. Connection settings come from the
|
|
PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE environment variables set by that
|
|
service (psycopg2.connect() reads them implicitly).
|
|
|
|
Keep every seed idempotent: it re-runs on every `docker compose up` (use
|
|
ON CONFLICT DO NOTHING / IF NOT EXISTS style upserts, stable uuids, ...).
|
|
"""
|
|
|
|
import psycopg2
|
|
|
|
|
|
def main():
|
|
conn = psycopg2.connect()
|
|
cur = conn.cursor()
|
|
cur.execute("SELECT 1")
|
|
cur.fetchone()
|
|
cur.close()
|
|
conn.close()
|
|
print("001_seed_example.py: no-op seed. Replace with real seeds.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|