我们正在以每个租户一个数据库的方式设计SaaS系统。当新租户注册时,会创建一个新数据库,并且需要设置数据库结构(方案,挂钩,功能和系统数据)。
现在,我想到了两个解决方案:从模型数据库复制/复制到新数据库,或者基于SQL脚本设置新数据库。我对OrientDB很新鲜,所以我重视你的任何建议。
提前致谢。
答案 0 :(得分:0)
我建议你这些选择:
创建第一个数据库(我使用了以下OSQL
脚本):
connect remote:localhost/BatchTest root root
CREATE CLASS Customer EXTENDS V
CREATE PROPERTY Customer.customerID INTEGER
CREATE PROPERTY Customer.State STRING
CREATE CLASS Store EXTENDS V
CREATE PROPERTY Store.storeID INTEGER
CREATE PROPERTY Store.State STRING
CREATE PROPERTY Store.Zip INTEGER
CREATE CLASS transaction EXTENDS E
CREATE PROPERTY transaction.amt DOUBLE
CREATE PROPERTY transaction.storeID INTEGER
CREATE PROPERTY transaction.customerID INTEGER
<强>数据集强>:
orientdb {db=BatchTest}> select from v
----+-----+--------+----------+-----+---------------+-------+----+--------------
# |@RID |@CLASS |customerID|State|out_transaction|storeID|Zip |in_transaction
----+-----+--------+----------+-----+---------------+-------+----+--------------
0 |#12:0|Customer|1 |NY |[size=4] |null |null|null
1 |#12:1|Customer|2 |NJ |[size=2] |null |null|null
2 |#12:2|Customer|3 |PA |[size=2] |null |null|null
3 |#12:3|Customer|4 |NY |[size=4] |null |null|null
4 |#12:4|Customer|5 |NY |[size=2] |null |null|null
5 |#13:0|Store |null |NY |null |1 |1 |[size=4]
6 |#13:1|Store |null |NJ |null |2 |3 |[size=6]
7 |#13:2|Store |null |NY |null |3 |2 |[size=4]
----+-----+--------+----------+-----+---------------+-------+----+--------------
<强>类/记录强>:
orientdb {db=BatchTest}> list classes
CLASSES
----------------------------------------------+------------------------------------+------------+----------------+
NAME | SUPERCLASS | CLUSTERS | RECORDS |
----------------------------------------------+------------------------------------+------------+----------------+
_studio | | 11 | 1 |
Customer | [V] | 12 | 5 |
E | | 10 | 0 |
OFunction | | 6 | 0 |
OIdentity | | - | 0 |
ORestricted | | - | 0 |
ORIDs | | 8 | 0 |
ORole | [OIdentity] | 4 | 3 |
OSchedule | | 7 | 0 |
OTriggered | | - | 0 |
OUser | [OIdentity] | 5 | 3 |
Store | [V] | 13 | 3 |
transaction | [E] | 14 | 14 |
V | | 9 | 0 |
----------------------------------------------+------------------------------------+------------+----------------+
TOTAL = 14 29 |
----------------------------------------------+------------------------------------+------------+----------------+
现在只复制没有数据集的结构:
OSQL
脚本以仅创建类/属性; 如果您选择第二种情况,则可以使用EXPORT
和IMPORT
命令以及相关参数。
连接到数据库以导出没有记录的结构(-includeRecords=false
):
orientdb {db=BatchTest}> export database C:/export/destination/path/exportTest.gz -includeRecords=false
Exporting current database to: database C:/export/destination/path/exportTest.gz -includeRecords=false in GZipped JSON format ...
Started export of database 'BatchTest' to C:/destination/path/exportTest.gz...
Exporting database info...OK
Exporting clusters...OK (15 clusters)
Exporting schema...OK (14 classes)
Exporting index info...
- Index OUser.name...OK
- Index dictionary...OK
- Index ORole.name...OK
OK (3 indexes)
Exporting manual indexes content...
- Exporting index dictionary ...OK (entries=0)
OK (1 manual indexes)
Database export completed in 55ms
创建一个新的空数据库:
orientdb> create database remote:localhost/importTest root root plocal
Creating database [remote:localhost/importTest] using the storage type [plocal]...
Connecting to database [remote:localhost/importTest] with user 'admin'...OK
Database created successfully.
Current database is: remote:localhost/importTest
导入导出的结构:
orientdb {db=importTest}> import database C:/path/to/exportTest.gz
Importing database database C:/path/to/exportTest.gz...
Started import of database 'remote:localhost/importTest' from C:/path/to/exportTest.gz...
Non merge mode (-merge=false): removing all default non security classes
- Class E was removed.
- Class V was removed.
- Class ORestricted was removed.
- Class OTriggered was removed.
- Class OSchedule was removed.
- Class ORIDs was removed.
- Class OFunction was removed.
Removed 7 classes.
Importing database info...OK
Importing clusters...
- Creating cluster 'internal'...OK, assigned id=0
- Creating cluster 'default'...OK, assigned id=3
- Creating cluster 'orole'...OK, assigned id=4
- Creating cluster 'ouser'...OK, assigned id=5
- Creating cluster 'ofunction'...OK, assigned id=6
- Creating cluster 'oschedule'...OK, assigned id=7
- Creating cluster 'orids'...OK, assigned id=8
- Creating cluster 'v'...OK, assigned id=9
- Creating cluster 'e'...OK, assigned id=10
- Creating cluster '_studio'...OK, assigned id=11
- Creating cluster 'customer'...OK, assigned id=12
- Creating cluster 'store'...OK, assigned id=13
- Creating cluster 'transaction'...OK, assigned id=14
Rebuilding indexes of truncated clusters ...
Done 2 indexes were rebuilt.
Done. Imported 13 clusters
Importing database schema...OK (14 classes)
Importing indexes ...
- Index 'OUser.name'...OK
- Index 'dictionary'...OK
- Index 'ORole.name'...OK
Done. Created 3 indexes.
Importing manual index entries...
- Index 'dictionary'...OK (0 entries)
Done. Imported 1 indexes.
Rebuild of stale indexes...
Stale indexes were rebuilt...
Deleting RID Mapping table...OK
Database import completed in 7501 ms
orientdb {db=importTest}> list classes
<强>结构:强>
CLASSES
----------------------------------------------+------------------------------------+------------+----------------+
NAME | SUPERCLASS | CLUSTERS | RECORDS |
----------------------------------------------+------------------------------------+------------+----------------+
_studio | | 11 | 0 |
Customer | [V] | 12 | 0 |
E | | 10 | 0 |
OFunction | | 6 | 0 |
OIdentity | | - | 0 |
ORestricted | | - | 0 |
ORIDs | | 8 | 0 |
ORole | [OIdentity] | 4 | 0 |
OSchedule | | 7 | 0 |
OTriggered | | - | 0 |
OUser | [OIdentity] | 5 | 0 |
Store | [V] | 13 | 0 |
transaction | [E] | 14 | 0 |
V | | 9 | 0 |
----------------------------------------------+------------------------------------+------------+----------------+
TOTAL = 14 0 |
----------------------------------------------+------------------------------------+------------+----------------+
<强>数据集:强>
orientdb {db=importTest}> select from v
0 item(s) found. Query executed in 0.004 sec(s).
您可以使用大量参数(official OrientDB documentation)自定义导出的数据库。
希望有所帮助