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
58e2ec2b
Commit
58e2ec2b
authored
7 years ago
by
furion
Browse files
Options
Downloads
Patches
Plain Diff
add sqlalchemy schema
parent
98f19814
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Dockerfile
+2
-1
2 additions, 1 deletion
Dockerfile
Makefile
+3
-0
3 additions, 0 deletions
Makefile
scripts/schema.py
+184
-32
184 additions, 32 deletions
scripts/schema.py
scripts/test.py
+0
-33
0 additions, 33 deletions
scripts/test.py
setup.py
+3
-1
3 additions, 1 deletion
setup.py
with
192 additions
and
67 deletions
Dockerfile
+
2
−
1
View file @
58e2ec2b
...
...
@@ -5,7 +5,8 @@ COPY . /src
WORKDIR
/src
RUN
pip
install
ipython
RUN
pip
install
-r
requirements.txt
#RUN pip install -r dev-requirements.txt
RUN
pip
install
-e
.
EXPOSE
5000
...
...
This diff is collapsed.
Click to expand it.
Makefile
+
3
−
0
View file @
58e2ec2b
...
...
@@ -15,6 +15,9 @@ build:
run
:
docker run
$(
PROJECT_DOCKER_RUN_ARGS
)
$(
PROJECT_DOCKER_TAG
)
ipython
:
docker
run
-it
$(PROJECT_DOCKER_TAG)
ipython
test
:
test-without-build build
test-without-build
:
test-without-lint test-pylint
...
...
This diff is collapsed.
Click to expand it.
scripts/schema.py
+
184
−
32
View file @
58e2ec2b
import
datetime
as
dt
from
sqlalchemy
import
(
Column
,
Integer
,
MetaData
,
Table
,
DateTime
,
Index
,
)
from
sqlalchemy
import
create_engine
from
sqlalchemy.dialects.mysql
import
SMALLINT
metadata
=
MetaData
()
addresses
=
Table
(
'
hive_blocks
'
,
metadata
,
Column
(
'
num
'
,
Integer
,
primary_key
=
True
),
Column
(
'
prev
'
,
Integer
),
Column
(
'
txs
'
,
SMALLINT
(
unsigned
=
True
),
default
=
0
),
Column
(
'
created_at
'
,
DateTime
),
Index
(
'
hive_blocks_ux1
'
,
'
prev
'
,
unique
=
True
),
# ForeignKeyConstraint(name='hive_blocks_fk1', columns='prev', refcolumns='hive_blocks.num'),
mysql_engine
=
'
InnoDB
'
,
mysql_charset
=
'
utf8mb4
'
,
import
logging
import
sqlalchemy
as
sa
from
sqlalchemy.dialects.mysql
import
(
CHAR
,
SMALLINT
,
TINYINT
,
TINYTEXT
,
DOUBLE
,
)
if
__name__
==
'
__main__
'
:
engine
=
create_engine
(
'
sqlite:///hive.sqlite
'
,
echo
=
True
)
metadata
.
create_all
(
engine
)
engine
.
execute
(
addresses
.
insert
([
addresses
.
c
.
num
,
addresses
.
c
.
prev
,
addresses
.
c
.
created_at
]).
values
(
num
=
0
,
prev
=
None
,
created_at
=
dt
.
datetime
.
fromtimestamp
(
0
)))
# INSERT INTO hive_blocks (num, prev, created_at) VALUES (0, NULL, "1970-01-01T00:00:00");
connection_url
=
'
mysql://root:root_password@localhost: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
,
sa
.
Column
(
'
num
'
,
sa
.
Integer
,
primary_key
=
True
),
sa
.
Column
(
'
prev
'
,
sa
.
Integer
),
sa
.
Column
(
'
txs
'
,
SMALLINT
(
unsigned
=
True
),
server_default
=
'
0
'
,
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
UniqueConstraint
(
'
prev
'
,
name
=
'
hive_blocks_ux1
'
),
sa
.
ForeignKeyConstraint
([
'
prev
'
],
[
'
hive_blocks.num
'
],
name
=
'
hive_blocks_fk1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_accounts
=
sa
.
Table
(
'
hive_accounts
'
,
metadata
,
sa
.
Column
(
'
id
'
,
sa
.
Integer
,
primary_key
=
True
),
sa
.
Column
(
'
name
'
,
sa
.
String
(
16
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
UniqueConstraint
(
'
name
'
,
name
=
'
hive_accounts_ux1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
# The column 'permlink' is CHAR(190) instead of CHAR(255) since the latter
# will give error: (1071, 'Specified key was too long; max key length is 767 bytes')
hive_posts
=
sa
.
Table
(
'
hive_posts
'
,
metadata
,
sa
.
Column
(
'
id
'
,
sa
.
Integer
,
primary_key
=
True
),
sa
.
Column
(
'
parent_id
'
,
sa
.
Integer
),
sa
.
Column
(
'
author
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
permlink
'
,
CHAR
(
190
),
nullable
=
False
),
sa
.
Column
(
'
community
'
,
CHAR
(
16
)),
sa
.
Column
(
'
category
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
depth
'
,
SMALLINT
(
unsigned
=
True
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Column
(
'
is_deleted
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
is_pinned
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
is_muted
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
ForeignKeyConstraint
([
'
author
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_posts_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
community
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_posts_fk2
'
),
sa
.
ForeignKeyConstraint
([
'
parent_id
'
],
[
'
hive_posts.id
'
],
name
=
'
hive_posts_fk3
'
),
sa
.
UniqueConstraint
(
'
author
'
,
'
permlink
'
,
name
=
'
hive_posts_ux1
'
),
sa
.
Index
(
'
hive_posts_ix1
'
,
'
parent_id
'
),
sa
.
Index
(
'
hive_posts_ix2
'
,
'
is_deleted
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_follows
=
sa
.
Table
(
'
hive_follows
'
,
metadata
,
sa
.
Column
(
'
follower
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
following
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'
follower
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_follows_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
following
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_follows_fk2
'
),
sa
.
UniqueConstraint
(
'
follower
'
,
'
following
'
,
name
=
'
hive_follows_ux1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_reblogs
=
sa
.
Table
(
'
hive_reblogs
'
,
metadata
,
sa
.
Column
(
'
account
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
post_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'
account
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_reblogs_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
],
name
=
'
hive_reblogs_fk2
'
),
sa
.
UniqueConstraint
(
'
account
'
,
'
post_id
'
,
name
=
'
hive_reblogs_ux1
'
),
sa
.
Index
(
'
hive_reblogs_ix1
'
,
'
post_id
'
,
'
account
'
,
'
created_at
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_communities
=
sa
.
Table
(
'
hive_communities
'
,
metadata
,
sa
.
Column
(
'
name
'
,
CHAR
(
16
),
primary_key
=
True
),
sa
.
Column
(
'
title
'
,
sa
.
String
(
32
),
nullable
=
False
),
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
(
'
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
),
sa
.
ForeignKeyConstraint
([
'
name
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_communities_fk1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_members
=
sa
.
Table
(
'
hive_members
'
,
metadata
,
sa
.
Column
(
'
community
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
account
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
is_admin
'
,
TINYINT
(
1
),
nullable
=
False
),
sa
.
Column
(
'
is_mod
'
,
TINYINT
(
1
),
nullable
=
False
),
sa
.
Column
(
'
is_approved
'
,
TINYINT
(
1
),
nullable
=
False
),
sa
.
Column
(
'
is_muted
'
,
TINYINT
(
1
),
nullable
=
False
),
sa
.
Column
(
'
title
'
,
sa
.
String
(
255
),
nullable
=
False
,
server_default
=
''
),
sa
.
ForeignKeyConstraint
([
'
community
'
],
[
'
hive_communities.name
'
],
name
=
'
hive_members_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
account
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_members_fk2
'
),
sa
.
UniqueConstraint
(
'
community
'
,
'
account
'
,
name
=
'
hive_members_ux1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_flags
=
sa
.
Table
(
'
hive_flags
'
,
metadata
,
sa
.
Column
(
'
account
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
post_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Column
(
'
notes
'
,
sa
.
String
(
255
),
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'
account
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_flags_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
],
name
=
'
hive_flags_fk2
'
),
sa
.
UniqueConstraint
(
'
account
'
,
'
post_id
'
,
name
=
'
hive_flags_ux1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_modlog
=
sa
.
Table
(
'
hive_modlog
'
,
metadata
,
sa
.
Column
(
'
id
'
,
sa
.
Integer
,
primary_key
=
True
),
sa
.
Column
(
'
community
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
account
'
,
CHAR
(
16
),
nullable
=
False
),
sa
.
Column
(
'
action
'
,
sa
.
String
(
32
),
nullable
=
False
),
sa
.
Column
(
'
params
'
,
sa
.
String
(
1000
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'
community
'
],
[
'
hive_communities.name
'
],
name
=
'
hive_modlog_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
account
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_modlog_fk2
'
),
sa
.
Index
(
'
hive_modlog_ix1
'
,
'
community
'
,
'
created_at
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_posts_cache
=
sa
.
Table
(
'
hive_posts_cache
'
,
metadata
,
sa
.
Column
(
'
post_id
'
,
sa
.
Integer
,
primary_key
=
True
),
sa
.
Column
(
'
title
'
,
sa
.
String
(
255
),
nullable
=
False
),
sa
.
Column
(
'
preview
'
,
sa
.
String
(
1024
),
nullable
=
False
),
sa
.
Column
(
'
img_url
'
,
sa
.
String
(
1024
),
nullable
=
False
),
sa
.
Column
(
'
payout
'
,
sa
.
types
.
DECIMAL
(
10
,
3
),
nullable
=
False
),
sa
.
Column
(
'
promoted
'
,
sa
.
types
.
DECIMAL
(
10
,
3
),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Column
(
'
payout_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
Column
(
'
is_nsfw
'
,
TINYINT
(
1
),
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
children
'
,
sa
.
Integer
,
nullable
=
False
,
server_default
=
'
0
'
),
sa
.
Column
(
'
rshares
'
,
sa
.
BigInteger
,
nullable
=
False
),
sa
.
Column
(
'
sc_trend
'
,
DOUBLE
,
nullable
=
False
),
sa
.
Column
(
'
sc_hot
'
,
DOUBLE
,
nullable
=
False
),
sa
.
Column
(
'
body
'
,
sa
.
Text
),
sa
.
Column
(
'
votes
'
,
sa
.
Text
),
sa
.
Column
(
'
json
'
,
sa
.
Text
),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
],
name
=
'
hive_posts_cache_fk1
'
),
sa
.
Index
(
'
hive_posts_cache_ix1
'
,
'
payout
'
),
sa
.
Index
(
'
hive_posts_cache_ix2
'
,
'
promoted
'
),
sa
.
Index
(
'
hive_posts_cache_ix3
'
,
'
payout_at
'
),
sa
.
Index
(
'
hive_posts_cache_ix4
'
,
'
updated_at
'
),
sa
.
Index
(
'
hive_posts_cache_ix5
'
,
'
rshares
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
hive_accounts_cache
=
sa
.
Table
(
'
hive_accounts_cache
'
,
metadata
,
sa
.
Column
(
'
account
'
,
CHAR
(
16
),
primary_key
=
True
),
sa
.
Column
(
'
reputation
'
,
sa
.
Float
,
nullable
=
False
,
server_default
=
'
25
'
),
sa
.
Column
(
'
name
'
,
sa
.
String
(
20
)),
sa
.
Column
(
'
about
'
,
sa
.
String
(
160
)),
sa
.
Column
(
'
location
'
,
sa
.
String
(
30
)),
sa
.
Column
(
'
url
'
,
sa
.
String
(
100
)),
sa
.
Column
(
'
img_url
'
,
sa
.
String
(
1024
)),
sa
.
ForeignKeyConstraint
([
'
account
'
],
[
'
hive_accounts.name
'
],
name
=
'
hive_accounts_cache_fk1
'
),
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
'
}
])
This diff is collapsed.
Click to expand it.
scripts/test.py
deleted
100644 → 0
+
0
−
33
View file @
98f19814
from
pprint
import
pprint
from
sqlalchemy
import
(
Column
,
Integer
,
MetaData
,
String
,
Table
,
create_engine
,
)
from
sqlalchemy
import
select
from
steem.account
import
Account
engine
=
create_engine
(
'
sqlite:///hive.sqlite
'
,
echo
=
True
)
metadata
=
MetaData
()
authors
=
Table
(
'
authors
'
,
metadata
,
Column
(
'
id
'
,
Integer
,
primary_key
=
True
,
autoincrement
=
True
),
Column
(
'
name
'
,
String
(
16
)),
Column
(
'
balances
'
,
String
),
)
metadata
.
create_all
(
engine
)
if
__name__
==
'
__main__
'
:
conn
=
engine
.
connect
()
acc
=
Account
(
'
furion
'
)
r
=
authors
.
insert
().
values
(
name
=
acc
.
name
,
balances
=
'
100
'
)
engine
.
execute
(
r
)
q
=
select
([
authors
])
pprint
(
conn
.
execute
(
q
).
fetchall
())
This diff is collapsed.
Click to expand it.
setup.py
+
3
−
1
View file @
58e2ec2b
...
...
@@ -25,10 +25,12 @@ setup(
'
pytest-console-scripts
'
],
install_requires
=
[
'
steem
==0.18.1
'
,
'
steem
'
,
'
maya
'
,
'
toolz
'
,
'
funcy
'
,
'
sqlalchemy
'
,
'
mysqlclient
'
,
],
entry_points
=
{
'
console_scripts
'
:
[
...
...
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