Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
physical
Commits
817f5a24
Commit
817f5a24
authored
Jan 24, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add DERouter
parent
20db121d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
13 deletions
+58
-13
DBRouter.py
physical/DBRouter.py
+43
-0
settings.py
physical/settings.py
+15
-13
No files found.
physical/DBRouter.py
0 → 100644
View file @
817f5a24
# !/usr/bin/env python
# -*- coding: utf-8 -*-
class
DBRouter
:
"""
A router to control all database operations on models in the
user application.
"""
def
db_for_read
(
self
,
model
,
**
hints
):
"""
Attempts to read user models go to users_db.
"""
if
model
.
_meta
.
app_label
==
'face'
:
return
'face'
return
None
def
db_for_write
(
self
,
model
,
**
hints
):
"""
Attempts to write user models go to users_db.
"""
if
model
.
_meta
.
app_label
==
'face'
:
return
'face'
return
None
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
"""
Allow relations if a model in the user app is involved.
"""
if
obj1
.
_meta
.
app_label
==
'face'
or
\
obj2
.
_meta
.
app_label
==
'face'
:
return
True
return
None
def
allow_migrate
(
self
,
db
,
app_label
,
model_name
=
None
,
**
hints
):
"""
Make sure the auth app only appears in the 'users_db'
database.
"""
if
app_label
==
'face'
:
return
db
==
'face'
return
None
physical/settings.py
View file @
817f5a24
...
...
@@ -18,7 +18,6 @@ from celery.schedules import crontab
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
...
...
@@ -30,9 +29,8 @@ DEBUG = False
ALLOWED_HOSTS
=
[]
# Application definition
SENTRY_CELERY_ENDPOINT
=
"http://60b0004c8884420f8067fb32fc3ed244:20f97fc73ffa4aad9735d0e6542a6d78@sentry.igengmei.com/140"
SENTRY_CELERY_ENDPOINT
=
"http://60b0004c8884420f8067fb32fc3ed244:20f97fc73ffa4aad9735d0e6542a6d78@sentry.igengmei.com/140"
BROKER_URL
=
"redis://127.0.0.1:6379/8"
# CELERY_SEND_EVENTS = True
...
...
@@ -64,8 +62,8 @@ INSTALLED_APPS = (
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'trans2es'
,
'search'
,
'trans2es'
,
'search'
,
'injection.data_sync'
,
)
...
...
@@ -125,13 +123,16 @@ REDIS_URL = "redis://127.0.0.1:6379"
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASE_ROUTERS
=
[
'physical.DBRouter.DBRouter'
]
DATABASES
=
{
'default'
:
{
'ENGINE'
:
'django.db.backends.mysql'
,
'NAME'
:
'alpha'
,
'USER'
:
'work'
,
'PASSWORD'
:
'Gengmei123'
,
'HOST'
:
'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com'
,
# 'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
"HOST"
:
'rm-2zeaut61u9sm21m0bjo.mysql.rds.aliyuncs.com'
,
'PORT'
:
'3306'
,
'OPTIONS'
:
{
"init_command"
:
"SET foreign_key_checks = 0;"
,
...
...
@@ -143,9 +144,10 @@ DATABASES = {
'NAME'
:
'face'
,
'USER'
:
'work'
,
'PASSWORD'
:
'Gengmei123'
,
'HOST'
:
'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com'
,
# 'HOST': 'rm-2ze5k2we69904787l.mysql.rds.aliyuncs.com',
"HOST"
:
"rm-2zeaut61u9sm21m0bjo.mysql.rds.aliyuncs.com"
,
'PORT'
:
'3306'
,
#'CONN_MAX_AGE': None,
#
'CONN_MAX_AGE': None,
'OPTIONS'
:
{
"init_command"
:
"SET foreign_key_checks = 0;"
,
"charset"
:
"utf8mb4"
,
...
...
@@ -154,13 +156,13 @@ DATABASES = {
}
ES_INFO_LIST
=
[
{
"host"
:
"10.29.130.141"
,
"port"
:
9200
}
{
"host"
:
"10.29.130.141"
,
"port"
:
9200
}
]
ES_INDEX_PREFIX
=
"gm-dbmw"
ES_INDEX_PREFIX
=
"gm-dbmw"
MIDDLEWARE_CLASSES
=
(
'gm_tracer.middleware.TracerMiddleware'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment