Extra support for configuring postgres
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from os.path import join
|
||||
|
||||
from synapse.config.database import DatabaseConfig
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
from synapse.config.logger import LoggingConfig
|
||||
from synapse.config.server import ServerConfig
|
||||
from synapse.config.tls import TlsConfig
|
||||
from synapse.config.logger import LoggingConfig
|
||||
from synapse.config.homeserver import HomeServerConfig
|
||||
|
||||
|
||||
def create_config(config_dir_path, data_dir_path, conf):
|
||||
@@ -12,6 +14,14 @@ def create_config(config_dir_path, data_dir_path, conf):
|
||||
server_config_in_use = conf["server_config_in_use"]
|
||||
del conf["server_config_in_use"]
|
||||
|
||||
database_conf = conf["database"]
|
||||
del conf["database"]
|
||||
|
||||
if database_conf["name"] == "sqlite3":
|
||||
database_conf.setdefault(
|
||||
"args", {"database": join(data_dir_path, "homeserver.db")}
|
||||
)
|
||||
|
||||
base_configs = [ServerConfig, DatabaseConfig, TlsConfig]
|
||||
|
||||
# Generate configs for all the ones we didn't cover explicitely
|
||||
@@ -30,6 +40,7 @@ def create_config(config_dir_path, data_dir_path, conf):
|
||||
"data_dir_path": data_dir_path,
|
||||
"server_name": server_name,
|
||||
**conf,
|
||||
"database_conf": database_conf,
|
||||
}
|
||||
|
||||
base_config = BaseConfig().generate_config(**config_args)
|
||||
@@ -41,4 +52,3 @@ def create_config(config_dir_path, data_dir_path, conf):
|
||||
+ "\n\nserver_config_in_use: {}".format(server_config_in_use),
|
||||
"the_rest.yaml": rest_of_config,
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,14 @@ BASE_CONFIG_SCHEMA = {
|
||||
"pid_file": {"type": "string", "minlength": 1},
|
||||
"listeners": {"type": "array"},
|
||||
"acme": {"type": "object"},
|
||||
"database": {"type": "string", "minlength": 1},
|
||||
"database": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {"type": "string", "minlength": 1},
|
||||
"args": {"type": "object"},
|
||||
},
|
||||
"required": ["name"],
|
||||
},
|
||||
"tls_certificate_path": {"type": "string", "minlength": 1},
|
||||
"tls_private_key_path": {"type": "string", "minlength": 1},
|
||||
"server_config_in_use": {"type": "boolean"},
|
||||
|
||||
@@ -277,9 +277,9 @@ export const testingSynapsePorts = verifying => ({
|
||||
verifying,
|
||||
})
|
||||
|
||||
export const setDatabase = database => ({
|
||||
export const setDatabase = databaseConfig => ({
|
||||
type: SET_DATABASE,
|
||||
database,
|
||||
databaseConfig,
|
||||
})
|
||||
|
||||
export const writeConfig = (config, subConfigName) => {
|
||||
|
||||
@@ -13,6 +13,8 @@ import { DATABASE_UI } from '../reducers/ui-constants';
|
||||
import AccordionToggle from '../containers/AccordionToggle';
|
||||
|
||||
import { nextUI } from '../reducers/setup-ui-reducer';
|
||||
import Tabs from 'react-bootstrap/Tabs';
|
||||
import Tab from 'react-bootstrap/Tab';
|
||||
|
||||
export default ({
|
||||
onClick,
|
||||
@@ -21,6 +23,11 @@ export default ({
|
||||
const defaultDatabase = DATABASE_TYPES.POSTGRES;
|
||||
const [database, setDatabase] = useState(defaultDatabase)
|
||||
|
||||
const [databaseHost, setHost] = useState();
|
||||
const [postgresDatabase, setPostgresDatabase] = useState();
|
||||
const [databaseUsername, setUser] = useState();
|
||||
const [databasePassword, setPassword] = useState();
|
||||
|
||||
const toggle = useAccordionToggle(nextUI(DATABASE_UI));
|
||||
|
||||
return <Card>
|
||||
@@ -32,20 +39,72 @@ export default ({
|
||||
<p>Synapse can use either SQLite3 or Postgres as it's database.</p>
|
||||
<p>Postgres is recommended.</p>
|
||||
|
||||
<select defaultValue={defaultDatabase}
|
||||
onChange={event => setDatabase(event.target.value)}
|
||||
>
|
||||
<option value={DATABASE_TYPES.POSTGRES}>PostgreSQL</option>
|
||||
<option value={DATABASE_TYPES.SQLITE3}>SQLite3</option>
|
||||
</select>
|
||||
<button
|
||||
className='inputButton'
|
||||
onClick={() => {
|
||||
toggle();
|
||||
onClick(database)
|
||||
}}>Next</button>
|
||||
<Tabs defaultActiveKey={defaultDatabase} onSelect={k => setDatabase(k)}>
|
||||
<Tab eventKey={DATABASE_TYPES.POSTGRES} title={DATABASE_TYPES.POSTGRES}>
|
||||
<p>
|
||||
Host
|
||||
</p>
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => setHost(e.target.value)}
|
||||
autoFocus
|
||||
placeholder="localhost"
|
||||
/>
|
||||
<p>
|
||||
Database name
|
||||
</p>
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => setPostgresDatabase(e.target.value)}
|
||||
autoFocus
|
||||
placeholder="unspecified"
|
||||
/>
|
||||
<p>
|
||||
User name
|
||||
</p>
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => setUser(e.target.value)}
|
||||
autoFocus
|
||||
placeholder="unspecified"
|
||||
/>
|
||||
<p>
|
||||
Password
|
||||
</p>
|
||||
<input
|
||||
type="text"
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
autoFocus
|
||||
placeholder="unspecified"
|
||||
/>
|
||||
<button
|
||||
className='inputButton'
|
||||
onClick={() => {
|
||||
toggle();
|
||||
onClick({
|
||||
databaseType: DATABASE_TYPES.POSTGRES,
|
||||
databaseHost,
|
||||
database: postgresDatabase,
|
||||
databaseUsername,
|
||||
databasePassword,
|
||||
})
|
||||
}}
|
||||
>Use {DATABASE_TYPES.POSTGRES}</button>
|
||||
</Tab>
|
||||
<Tab eventKey={DATABASE_TYPES.SQLITE3} title={DATABASE_TYPES.SQLITE3}>
|
||||
<button
|
||||
className='inputButton'
|
||||
onClick={() => {
|
||||
toggle();
|
||||
onClick({
|
||||
databaseType: DATABASE_TYPES.SQLITE3
|
||||
});
|
||||
}}
|
||||
>Use {DATABASE_TYPES.SQLITE3}</button>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
</Card.Body>
|
||||
</Accordion.Collapse>
|
||||
</Card>
|
||||
</Card >
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ const mapStateToProps = (state) => {
|
||||
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
onClick: database => {
|
||||
onClick: databaseConfig => {
|
||||
|
||||
dispatch(setDatabase(database));
|
||||
dispatch(setDatabase(databaseConfig));
|
||||
dispatch(advanceUI());
|
||||
|
||||
},
|
||||
|
||||
@@ -127,7 +127,7 @@ export default (state, action) => {
|
||||
case SET_DATABASE:
|
||||
return {
|
||||
...state,
|
||||
database: action.database,
|
||||
...action.databaseConfig,
|
||||
}
|
||||
case SET_CONFIG_DIR:
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { TLS_TYPES, REVERSE_PROXY_TYPES } from '../actions/constants';
|
||||
import { TLS_TYPES, REVERSE_PROXY_TYPES, DATABASE_TYPES } from '../actions/constants';
|
||||
import { CONFIG_LOCK } from '../api/constants';
|
||||
|
||||
const listeners = config => {
|
||||
@@ -114,12 +114,35 @@ const acme = config => {
|
||||
|
||||
}
|
||||
|
||||
const database = config => {
|
||||
|
||||
if (config.databaseType == DATABASE_TYPES.SQLITE3) {
|
||||
return {
|
||||
database: {
|
||||
name: config.databaseType,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
database: {
|
||||
name: config.databaseType,
|
||||
args: {
|
||||
user: config.databaseUsername,
|
||||
password: config.databasePassword,
|
||||
host: config.databaseHost,
|
||||
database: config.database,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const baseConfigToSynapseConfig = config => {
|
||||
|
||||
const conf = {
|
||||
server_name: config.servername,
|
||||
report_stats: config.reportStats,
|
||||
database: config.database,
|
||||
...database(config),
|
||||
...listeners(config),
|
||||
...tlsPaths(config),
|
||||
...acme(config),
|
||||
|
||||
Reference in New Issue
Block a user