1
0

postgres_exec.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. import psycopg2
  17. # a very simple replacment for `psql`, to make up for the lack of the postgres client
  18. # libraries in the synapse docker image.
  19. # We use "postgres" as a database because it's bound to exist and the "synapse" one
  20. # doesn't exist yet.
  21. db_conn = psycopg2.connect(
  22. user="postgres", host="localhost", password="postgres", dbname="postgres"
  23. )
  24. db_conn.autocommit = True
  25. cur = db_conn.cursor()
  26. for c in sys.argv[1:]:
  27. cur.execute(c)