Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 69eea7d7
authored
Jun 25, 2026
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Oracle Dialect Init
1 parent
557aaf37
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
65 additions
and
31 deletions
opensipkd/base/__init__.py
opensipkd/base/alembic/env.py
opensipkd/base/alembic/versions/021a8a342d5b_init_db.py
opensipkd/base/alembic/versions/10a68b1510a6_.py
opensipkd/base/alembic/versions/663de8bbd563_text_printer_init.py
opensipkd/base/alembic/versions/8de8d8168688_create_test.py
opensipkd/base/models/base.py
opensipkd/base/models/departmen.py
opensipkd/base/models/handlers.py
opensipkd/base/scripts/data/users_groups.csv
opensipkd/base/scripts/initializedb.py
opensipkd/base/__init__.py
View file @
69eea7d
...
@@ -27,7 +27,7 @@ from .models.handlers import LogDBSession
...
@@ -27,7 +27,7 @@ from .models.handlers import LogDBSession
from
.models.meta
import
Base
from
.models.meta
import
Base
from
.models.users
import
init_model
from
.models.users
import
init_model
from
.models
import
Route
from
.models
import
Route
# from .models import TABLE_ARGS
# from deform import ZPTRendererFactory, Form
# from deform import ZPTRendererFactory, Form
# from deform.widget import default_resource_registry
# from deform.widget import default_resource_registry
...
@@ -302,10 +302,24 @@ def get_config(settings):
...
@@ -302,10 +302,24 @@ def get_config(settings):
return
config
return
config
# def get_schema_for_dialect(engine_dialect_name: str) -> str | None:
# """Returns 'public' for PostgreSQL or None for Oracle to match native defaults."""
# if "postgresql" in engine_dialect_name.lower():
# return "public"
# return None # Triggers default user-schema fallback on Oracle
def
init_db
(
settings
):
def
init_db
(
settings
):
engine
=
engine_from_config
(
engine
=
engine_from_config
(
settings
,
'sqlalchemy.'
,
client_encoding
=
'utf8'
,
settings
,
'sqlalchemy.'
,
client_encoding
=
'utf8'
,
max_identifier_length
=
30
)
# , convert_unicode=True
max_identifier_length
=
30
)
# , convert_unicode=True
# global TABLE_ARGS
# # Resolve the target schema namespace dynamically based on active engine
# TABLE_ARGS = dict(extend_existing=True,
# schema=get_schema_for_dialect(engine.dialect.name))
DBSession
.
configure
(
bind
=
engine
)
DBSession
.
configure
(
bind
=
engine
)
LogDBSession
.
configure
(
bind
=
engine
)
LogDBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
bind
=
engine
Base
.
metadata
.
bind
=
engine
...
...
opensipkd/base/alembic/env.py
View file @
69eea7d
import
logging
from
logging.config
import
fileConfig
from
logging.config
import
fileConfig
from
sqlalchemy
import
engine_from_config
from
sqlalchemy
import
engine_from_config
...
@@ -11,6 +12,19 @@ from opensipkd.models import Base
...
@@ -11,6 +12,19 @@ from opensipkd.models import Base
config
=
context
.
config
config
=
context
.
config
# Interpret the config file for Python logging.
# Interpret the config file for Python logging.
# This line sets up loggers basically.
# This line sets up loggers basically.
log
=
logging
.
getLogger
(
__name__
)
url
=
config
.
get_main_option
(
"sqlalchemy.url"
)
if
url
.
find
(
"oracledb"
)
>
-
1
:
log
.
error
(
"OracleDB used:
%
s"
,
url
)
try
:
import
oracledb
lib_dir
=
config
.
get_main_option
(
"lib_dir"
)
if
lib_dir
:
oracledb
.
init_oracle_client
(
lib_dir
=
lib_dir
)
except
Exception
as
e
:
log
.
error
(
f
"An error occurred: {str(e)}"
)
log
.
error
(
"Oracle not initialize"
)
if
config
.
config_file_name
is
not
None
:
if
config
.
config_file_name
is
not
None
:
fileConfig
(
config
.
config_file_name
)
fileConfig
(
config
.
config_file_name
)
...
...
opensipkd/base/alembic/versions/021a8a342d5b_init_db.py
View file @
69eea7d
This diff is collapsed.
Click to expand it.
opensipkd/base/alembic/versions/10a68b1510a6_.py
View file @
69eea7d
...
@@ -31,7 +31,7 @@ def upgrade():
...
@@ -31,7 +31,7 @@ def upgrade():
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_eselon'
)),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_eselon'
)),
schema
=
'public'
#
schema='public'
)
)
op
.
create_table
(
'pangkat'
,
op
.
create_table
(
'pangkat'
,
sa
.
Column
(
'pangkat'
,
sa
.
String
(
length
=
32
),
nullable
=
True
),
sa
.
Column
(
'pangkat'
,
sa
.
String
(
length
=
32
),
nullable
=
True
),
...
@@ -45,7 +45,7 @@ def upgrade():
...
@@ -45,7 +45,7 @@ def upgrade():
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_pangkat'
)),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_pangkat'
)),
schema
=
'public'
#
schema='public'
)
)
op
.
create_table
(
'jabatan'
,
op
.
create_table
(
'jabatan'
,
sa
.
Column
(
'jenis'
,
sa
.
SmallInteger
(),
nullable
=
True
),
sa
.
Column
(
'jenis'
,
sa
.
SmallInteger
(),
nullable
=
True
),
...
@@ -62,10 +62,10 @@ def upgrade():
...
@@ -62,10 +62,10 @@ def upgrade():
sa
.
Column
(
'create_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'create_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'eselon_id'
],
[
'
public.
eselon.id'
],
name
=
op
.
f
(
sa
.
ForeignKeyConstraint
([
'eselon_id'
],
[
'eselon.id'
],
name
=
op
.
f
(
'fk_jabatan_eselon_id_eselon'
)),
'fk_jabatan_eselon_id_eselon'
)),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_jabatan'
)),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_jabatan'
)),
schema
=
'public'
#
schema='public'
)
)
op
.
create_table
(
'partner_departemen'
,
op
.
create_table
(
'partner_departemen'
,
sa
.
Column
(
'partner_id'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'partner_id'
,
sa
.
Integer
(),
nullable
=
True
),
...
@@ -74,9 +74,9 @@ def upgrade():
...
@@ -74,9 +74,9 @@ def upgrade():
sa
.
Column
(
'mulai'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'mulai'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'selesai'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'selesai'
,
sa
.
DateTime
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
ForeignKeyConstraint
([
'departemen_id'
],
[
'
public.
departemen.id'
],
name
=
op
.
f
(
sa
.
ForeignKeyConstraint
([
'departemen_id'
],
[
'departemen.id'
],
name
=
op
.
f
(
'fk_partner_departemen_departemen_id_departemen'
)),
'fk_partner_departemen_departemen_id_departemen'
)),
sa
.
ForeignKeyConstraint
([
'jabatan_id'
],
[
'
public.
jabatan.id'
],
name
=
op
.
f
(
sa
.
ForeignKeyConstraint
([
'jabatan_id'
],
[
'jabatan.id'
],
name
=
op
.
f
(
'fk_partner_departemen_jabatan_id_jabatan'
)),
'fk_partner_departemen_jabatan_id_jabatan'
)),
sa
.
ForeignKeyConstraint
([
'partner_id'
],
[
'partner.id'
],
name
=
op
.
f
(
sa
.
ForeignKeyConstraint
([
'partner_id'
],
[
'partner.id'
],
name
=
op
.
f
(
'fk_partner_departemen_partner_id_partner'
)),
'fk_partner_departemen_partner_id_partner'
)),
...
@@ -84,15 +84,15 @@ def upgrade():
...
@@ -84,15 +84,15 @@ def upgrade():
'id'
,
name
=
op
.
f
(
'pk_partner_departemen'
)),
'id'
,
name
=
op
.
f
(
'pk_partner_departemen'
)),
sa
.
UniqueConstraint
(
'partner_id'
,
'departemen_id'
,
sa
.
UniqueConstraint
(
'partner_id'
,
'departemen_id'
,
'jabatan_id'
,
'mulai'
,
name
=
'partner_dept_uq'
),
'jabatan_id'
,
'mulai'
,
name
=
'partner_dept_uq'
),
schema
=
'public'
#
schema='public'
)
)
# ### end Alembic commands ###
# ### end Alembic commands ###
def
downgrade
():
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
# ### commands auto generated by Alembic - please adjust! ###
op
.
drop_table
(
'partner_departemen'
,
schema
=
'public'
)
op
.
drop_table
(
'partner_departemen'
,
)
#
schema='public')
op
.
drop_table
(
'jabatan'
,
schema
=
'public'
)
op
.
drop_table
(
'jabatan'
,
)
#
schema='public')
op
.
drop_table
(
'pangkat'
,
schema
=
'public'
)
op
.
drop_table
(
'pangkat'
,
)
#
schema='public')
op
.
drop_table
(
'eselon'
,
schema
=
'public'
)
op
.
drop_table
(
'eselon'
,
)
#
schema='public')
# ### end Alembic commands ###
# ### end Alembic commands ###
opensipkd/base/alembic/versions/663de8bbd563_text_printer_init.py
View file @
69eea7d
...
@@ -32,12 +32,12 @@ def upgrade():
...
@@ -32,12 +32,12 @@ def upgrade():
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'update_uid'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'id'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_text_printers'
)),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_text_printers'
)),
schema
=
'public'
#
schema='public'
)
)
# ### end Alembic commands ###
# ### end Alembic commands ###
def
downgrade
():
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
# ### commands auto generated by Alembic - please adjust! ###
op
.
drop_table
(
'text_printers'
,
schema
=
'public'
)
op
.
drop_table
(
'text_printers'
,
)
#
schema='public')
# ### end Alembic commands ###
# ### end Alembic commands ###
opensipkd/base/alembic/versions/8de8d8168688_create_test.py
View file @
69eea7d
This diff is collapsed.
Click to expand it.
opensipkd/base/models/base.py
View file @
69eea7d
...
@@ -23,7 +23,8 @@ DBSession = scoped_session(session_factory)
...
@@ -23,7 +23,8 @@ DBSession = scoped_session(session_factory)
register
(
DBSession
)
register
(
DBSession
)
ziggurat_foundations
.
models
.
DBSession
=
DBSession
ziggurat_foundations
.
models
.
DBSession
=
DBSession
TABLE_ARGS
=
dict
(
extend_existing
=
True
,
schema
=
"public"
)
TABLE_ARGS
=
dict
(
extend_existing
=
True
,)
#schema="public")
def
flush
(
row
,
db_session
=
DBSession
):
def
flush
(
row
,
db_session
=
DBSession
):
...
...
opensipkd/base/models/departmen.py
View file @
69eea7d
...
@@ -5,9 +5,10 @@ from ..models import (NamaModel, TABLE_ARGS)
...
@@ -5,9 +5,10 @@ from ..models import (NamaModel, TABLE_ARGS)
class
_Departemen
(
NamaModel
):
class
_Departemen
(
NamaModel
):
__table_args__
=
(
TABLE_ARGS
,)
#
__table_args__ = (TABLE_ARGS,)
id
=
Column
(
Integer
,
primary_key
=
True
)
id
=
Column
(
Integer
,
primary_key
=
True
)
parent_id
=
Column
(
Integer
,
ForeignKey
(
'public.departemen.id'
))
# parent_id = Column(Integer, ForeignKey('public.departemen.id'))
parent_id
=
Column
(
Integer
,
ForeignKey
(
'departemen.id'
))
kategori
=
Column
(
String
(
32
))
kategori
=
Column
(
String
(
32
))
alamat
=
Column
(
String
(
255
))
alamat
=
Column
(
String
(
255
))
singkat
=
Column
(
String
(
32
))
singkat
=
Column
(
String
(
32
))
...
...
opensipkd/base/models/handlers.py
View file @
69eea7d
from
sqlalchemy
import
(
Column
,
Integer
,
String
,
DateTime
,
func
,
)
from
sqlalchemy
import
(
Column
,
Integer
,
String
,
DateTime
,
func
,
Text
)
from
sqlalchemy.orm
import
(
scoped_session
,
sessionmaker
,
)
from
sqlalchemy.orm
import
(
scoped_session
,
sessionmaker
,
)
from
..models.base
import
CommonModel
from
..models.base
import
CommonModel
from
..models.meta
import
Base
from
..models.meta
import
Base
...
@@ -11,9 +11,9 @@ class Log(Base, CommonModel):
...
@@ -11,9 +11,9 @@ class Log(Base, CommonModel):
__tablename__
=
'logs'
__tablename__
=
'logs'
id
=
Column
(
Integer
,
primary_key
=
True
)
# auto incrementing
id
=
Column
(
Integer
,
primary_key
=
True
)
# auto incrementing
line_id
=
Column
(
String
(
32
),
nullable
=
False
,
unique
=
True
)
line_id
=
Column
(
String
(
32
),
nullable
=
False
,
unique
=
True
)
logger
=
Column
(
String
)
# the name of the logger. (e.g. myapp.views)
logger
=
Column
(
Text
)
# the name of the logger. (e.g. myapp.views)
level
=
Column
(
String
)
# info, debug, or error?
level
=
Column
(
Text
)
# info, debug, or error?
trace
=
Column
(
String
)
# the full traceback printout
trace
=
Column
(
Text
)
# the full traceback printout
msg
=
Column
(
String
,
nullable
=
False
)
msg
=
Column
(
String
,
nullable
=
False
)
created_at
=
Column
(
created_at
=
Column
(
DateTime
(
timezone
=
True
),
DateTime
(
timezone
=
True
),
...
...
opensipkd/base/scripts/data/users_groups.csv
View file @
69eea7d
user_id/users.user_name,group_id/groups.group_name
user_id/users.user_name,group_id/groups.group_name
admin,Superuser
\ No newline at end of file
\ No newline at end of file
opensipkd/base/scripts/initializedb.py
View file @
69eea7d
...
@@ -115,6 +115,7 @@ def restore_csv(table, filename, get_file_func=get_file, db_session=DBSession):
...
@@ -115,6 +115,7 @@ def restore_csv(table, filename, get_file_func=get_file, db_session=DBSession):
eng
=
db_session
.
get_bind
()
eng
=
db_session
.
get_bind
()
q
=
db_session
.
query
(
table
)
q
=
db_session
.
query
(
table
)
if
q
.
first
():
if
q
.
first
():
log
.
error
(
"Restore discarded"
)
return
return
with
get_file_func
(
filename
)
as
f
:
with
get_file_func
(
filename
)
as
f
:
reader
=
csv
.
DictReader
(
f
)
reader
=
csv
.
DictReader
(
f
)
...
@@ -135,7 +136,7 @@ def restore_csv(table, filename, get_file_func=get_file, db_session=DBSession):
...
@@ -135,7 +136,7 @@ def restore_csv(table, filename, get_file_func=get_file, db_session=DBSession):
raise
e
raise
e
fname_orig
=
t
[
0
]
fname_orig
=
t
[
0
]
schema
=
"public"
schema
=
None
#
"public"
if
t
[
1
:]:
if
t
[
1
:]:
t_array
=
t
[
1
]
.
split
(
'.'
)
t_array
=
t
[
1
]
.
split
(
'.'
)
if
len
(
t_array
)
==
2
:
if
len
(
t_array
)
==
2
:
...
@@ -218,7 +219,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
...
@@ -218,7 +219,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
# print(dir(table.__table__))
# print(dir(table.__table__))
# print("____")
# print("____")
schema
=
hasattr
(
schema
=
hasattr
(
table
.
__table__
,
"schema"
)
and
table
.
__table__
.
schema
or
"public"
table
.
__table__
,
"schema"
)
and
table
.
__table__
.
schema
or
None
#
"public"
columns_table
=
insp
.
get_columns
(
table
.
__tablename__
,
schema
)
columns_table
=
insp
.
get_columns
(
table
.
__tablename__
,
schema
)
fields
=
{}
fields
=
{}
for
c
in
columns_table
:
for
c
in
columns_table
:
...
@@ -245,7 +246,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
...
@@ -245,7 +246,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
raise
e
raise
e
fname_orig
=
t
[
0
]
fname_orig
=
t
[
0
]
schema
=
"public"
schema
=
None
#
"public"
if
t
[
1
:]:
if
t
[
1
:]:
t_array
=
t
[
1
]
.
split
(
'.'
)
t_array
=
t
[
1
]
.
split
(
'.'
)
if
len
(
t_array
)
==
2
:
if
len
(
t_array
)
==
2
:
...
@@ -255,7 +256,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
...
@@ -255,7 +256,7 @@ def append_csv(table, filename, keys, get_file_func=get_file,
schema
=
t_array
[
0
]
schema
=
t_array
[
0
]
foreign_table
=
t_array
[
1
]
foreign_table
=
t_array
[
1
]
foreign_field
=
t_array
[
2
]
foreign_field
=
t_array
[
2
]
log
.
debug
(
"
%
s.
%
s"
,
schema
,
foreign_table
)
foreign_table
=
Table
(
foreign_table
,
base
.
metadata
,
foreign_table
=
Table
(
foreign_table
,
base
.
metadata
,
# autoload=True, # merubah v1.4 ke v.2
# autoload=True, # merubah v1.4 ke v.2
autoload_with
=
eng
,
autoload_with
=
eng
,
...
@@ -286,8 +287,8 @@ def append_csv(table, filename, keys, get_file_func=get_file,
...
@@ -286,8 +287,8 @@ def append_csv(table, filename, keys, get_file_func=get_file,
with
eng
.
connect
()
as
conn
:
with
eng
.
connect
()
as
conn
:
q
=
conn
.
execute
(
sql
)
q
=
conn
.
execute
(
sql
)
row
=
q
.
fetchone
()
row
=
q
.
fetchone
()
if
not
row
:
#
if not row:
raise
Exception
(
f
"Foreign key value '{value}' not found in table '{foreign_table.name}' for field '{fname}'"
)
#
raise Exception(f"Foreign key value '{value}' not found in table '{foreign_table.name}' for field '{fname}'")
value
=
row
and
row
.
id
or
None
value
=
row
and
row
.
id
or
None
q
.
close
()
q
.
close
()
# connection.close()
# connection.close()
...
@@ -377,8 +378,9 @@ def reset_sequence_(cls, seq):
...
@@ -377,8 +378,9 @@ def reset_sequence_(cls, seq):
def
reset_sequences
():
def
reset_sequences
():
reset_sequence_
(
User
,
'users_id_seq'
)
pass
reset_sequence_
(
Group
,
'groups_id_seq'
)
# reset_sequence_(User, 'users_id_seq')
# reset_sequence_(Group, 'groups_id_seq')
def
alembic_run
(
ini_file
,
name
=
None
):
def
alembic_run
(
ini_file
,
name
=
None
):
...
@@ -430,8 +432,9 @@ def main(argv=sys.argv):
...
@@ -430,8 +432,9 @@ def main(argv=sys.argv):
q
=
DBSession
.
query
(
User
)
.
filter_by
(
id
=
1
)
q
=
DBSession
.
query
(
User
)
.
filter_by
(
id
=
1
)
user
=
q
.
first
()
user
=
q
.
first
()
init_model
()
init_model
()
password
=
ask_password
(
user
.
user_name
)
if
user
:
UserService
.
set_password
(
user
,
password
)
password
=
ask_password
(
user
.
user_name
)
UserService
.
set_password
(
user
,
password
)
append_csv
(
Group
,
'groups.csv'
,
[
'group_name'
])
append_csv
(
Group
,
'groups.csv'
,
[
'group_name'
])
restore_csv
(
UserGroup
,
'users_groups.csv'
)
restore_csv
(
UserGroup
,
'users_groups.csv'
)
append_csv
(
Permission
,
'permissions.csv'
,
[
'perm_name'
])
append_csv
(
Permission
,
'permissions.csv'
,
[
'perm_name'
])
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment