mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-16 13:01:04 +02:00
Use the network name as the db schema (#185)
This commit is contained in:
parent
a3cd29f430
commit
30417987ba
2 changed files with 21 additions and 5 deletions
|
|
@ -138,6 +138,11 @@ def main():
|
|||
|
||||
|
||||
def run_server(config):
|
||||
# load the network
|
||||
network = load_network(config)
|
||||
logger.info("network: " + network)
|
||||
SelectParams(network)
|
||||
|
||||
# load the db params
|
||||
db_params = load_db_params(config)
|
||||
logger.info("db params: " + str(db_params))
|
||||
|
|
@ -146,13 +151,9 @@ def run_server(config):
|
|||
postgres_db = load_postgres_db(config)
|
||||
logger.info("postgres_db: " + str(postgres_db))
|
||||
postgres_db.get_version()
|
||||
postgres_db.create_schema(network)
|
||||
postgres_db.init()
|
||||
|
||||
# load the price
|
||||
network = load_network(config)
|
||||
logger.info("network: " + network)
|
||||
SelectParams(network)
|
||||
|
||||
# load the price
|
||||
price = load_price(config)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import logging
|
|||
from contextlib import contextmanager
|
||||
|
||||
from psycopg2 import pool
|
||||
from psycopg2 import sql
|
||||
from psycopg2.extras import DictCursor
|
||||
from squeak.core import CSqueak
|
||||
|
||||
|
|
@ -40,6 +41,20 @@ class PostgresDb:
|
|||
db_version = curs.fetchone()
|
||||
logger.info(db_version)
|
||||
|
||||
def create_schema(self, schema_name):
|
||||
""" Create the schema for the given name. """
|
||||
create_schema_sql = sql.SQL("CREATE SCHEMA {};").format(
|
||||
sql.Identifier(schema_name)
|
||||
)
|
||||
use_schema_sql = sql.SQL("SET search_path TO {}, public;").format(
|
||||
sql.Identifier(schema_name)
|
||||
)
|
||||
with self.get_cursor() as curs:
|
||||
# execute a statement
|
||||
logger.info("Creating schema: {}".format(schema_name))
|
||||
curs.execute(create_schema_sql)
|
||||
curs.execute(use_schema_sql)
|
||||
|
||||
def init(self):
|
||||
""" Create the tables and indices in the database. """
|
||||
with self.get_cursor() as curs:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue