Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
008de4c5
Commit
008de4c5
authored
8 years ago
by
furion
Browse files
Options
Downloads
Patches
Plain Diff
[schema] setup and teardown methods
parent
724f2c68
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+9
-0
9 additions, 0 deletions
README.md
scripts/schema.py
+33
-23
33 additions, 23 deletions
scripts/schema.py
with
42 additions
and
23 deletions
README.md
+
9
−
0
View file @
008de4c5
...
...
@@ -11,6 +11,15 @@ make build
make iypthon
```
Apply MySQL Schema (from REPL):
```
%run scripts/schema.py
```
MySQL Schema (from code):
see
`schema.setup()`
and
`schema.teardown()`
*Todo: Implement migrations via Alembic.*
## Hivemind
`hivemind`
is an off-chain consensus layer for Steem communities and API server for social features like feeds and follows.
...
...
This diff is collapsed.
Click to expand it.
scripts/schema.py
+
33
−
23
View file @
008de4c5
...
...
@@ -6,13 +6,6 @@ from sqlalchemy.dialects.mysql import (
TINYTEXT
,
DOUBLE
,
)
connection_url
=
'
mysql://root:root_password@db:3306/testdb
'
logging
.
basicConfig
()
logging
.
getLogger
(
'
sqlalchemy.engine
'
).
setLevel
(
logging
.
INFO
)
engine
=
sa
.
create_engine
(
connection_url
)
conn
=
engine
.
connect
()
metadata
=
sa
.
MetaData
()
hive_blocks
=
sa
.
Table
(
'
hive_blocks
'
,
metadata
,
...
...
@@ -83,7 +76,7 @@ hive_communities = sa.Table('hive_communities', metadata,
sa
.
Column
(
'
about
'
,
sa
.
String
(
255
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
description
'
,
sa
.
String
(
5000
),
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
lang
'
,
CHAR
(
2
),
nullable
=
False
,
server_default
=
'
en
'
),
sa
.
Column
(
'
settings
'
,
TINYTEXT
,
nullable
=
False
,
server_default
=
''
),
sa
.
Column
(
'
settings
'
,
TINYTEXT
,
nullable
=
False
),
sa
.
Column
(
'
type_id
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
is_nsfw
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
...
...
@@ -169,18 +162,35 @@ hive_accounts_cache = sa.Table('hive_accounts_cache', metadata,
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
metadata
.
drop_all
(
engine
)
metadata
.
create_all
(
engine
)
# Insert hive_blocks data
insert
=
hive_blocks
.
insert
().
values
(
num
=
0
,
prev
=
None
,
created_at
=
'
1970-01-01T00:00:00
'
)
conn
.
execute
(
insert
)
# Insert hive_accounts data
insert
=
hive_accounts
.
insert
()
conn
.
execute
(
insert
,
[
{
'
name
'
:
'
miners
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
null
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
temp
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
initminer
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
}
])
_url
=
'
mysql://root:root_password@db:3306/testdb
'
logging
.
basicConfig
()
logging
.
getLogger
(
'
sqlalchemy.engine
'
).
setLevel
(
logging
.
INFO
)
def
setup
(
connection_url
=
_url
):
engine
=
sa
.
create_engine
(
connection_url
)
metadata
.
create_all
(
engine
)
conn
=
engine
.
connect
()
# Insert hive_blocks data
insert
=
hive_blocks
.
insert
().
values
(
num
=
0
,
prev
=
None
,
created_at
=
'
1970-01-01T00:00:00
'
)
conn
.
execute
(
insert
)
# Insert hive_accounts data
insert
=
hive_accounts
.
insert
()
conn
.
execute
(
insert
,
[
{
'
name
'
:
'
miners
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
null
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
temp
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
},
{
'
name
'
:
'
initminer
'
,
'
created_at
'
:
'
1970-01-01T00:00:00
'
}
])
def
teardown
(
connection_url
=
_url
):
engine
=
sa
.
create_engine
(
connection_url
)
metadata
.
drop_all
(
engine
)
if
__name__
==
'
__main__
'
:
teardown
()
setup
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment