You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.3 KiB

  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 logging
  16. from synapse.storage.engines import create_engine
  17. logger = logging.getLogger("create_postgres_db")
  18. if __name__ == "__main__":
  19. # Create a PostgresEngine.
  20. db_engine = create_engine({"name": "psycopg2", "args": {}})
  21. # Connect to postgres to create the base database.
  22. # We use "postgres" as a database because it's bound to exist and the "synapse" one
  23. # doesn't exist yet.
  24. db_conn = db_engine.module.connect(
  25. user="postgres", host="postgres", password="postgres", dbname="postgres"
  26. )
  27. db_conn.autocommit = True
  28. cur = db_conn.cursor()
  29. cur.execute("CREATE DATABASE synapse;")
  30. cur.close()
  31. db_conn.close()