Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Oracle database support #641

Merged
merged 1 commit into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ jobs:
ports:
- 6379

oracle:
image: gvenzl/oracle-xe:18
ports:
- 1521
env:
ORACLE_PASSWORD: password
options: >-
--health-cmd healthcheck.sh
--health-interval 10s
--health-timeout 5s
--health-retries 10

steps:
- name: Set up dataset
run: |
Expand Down Expand Up @@ -123,8 +111,6 @@ jobs:
CLICKHOUSE_URI: clickhouse://localhost:${{ job.services.clickhouse.ports[8123] }}/
# Redis
REDIS_URI: redis://localhost:${{ job.services.redis.ports[6379] }}/
# Oracle
ORACLE_URI: oracle://system:[email protected]:${{ job.services.oracle.ports[1521] }}/XE

- name: Upload
run: bash <(curl -s https://codecov.io/bash)
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ The default database URLs are directed to these databases in `storage/docker-com
| `POSTGRES_URI` | `postgres://gorse:[email protected]/` |
| `MONGO_URI` | `mongodb://root:[email protected]:27017/` |
| `CLICKHOUSE_URI` | `clickhouse://127.0.0.1:8123/` |
| `ORACLE_URI` | `oracle://system:[email protected]:1521/XE` |
| `REDIS_URI` | `redis://127.0.0.1:6379/` |

For example, use TiDB as a test database by:
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/benhoyt/goawk v1.20.0
github.com/bits-and-blooms/bitset v1.2.1
github.com/chewxy/math32 v1.10.1
github.com/dzwvip/oracle v1.2.4
github.com/emicklei/go-restful-openapi/v2 v2.9.0
github.com/emicklei/go-restful/v3 v3.9.0
github.com/go-playground/locales v0.14.0
Expand Down Expand Up @@ -168,7 +167,6 @@ require (
)

replace (
github.com/dzwvip/oracle v1.2.4 => github.com/gorse-io/oracle v1.2.2-0.20220717033501-725373bd8ae8
gorm.io/driver/clickhouse v0.4.2 => github.com/gorse-io/clickhouse v0.3.3-0.20220715124633-688011a495bb
gorm.io/driver/sqlite v1.3.4 => github.com/gorse-io/sqlite v1.3.3-0.20220713123255-c322aec4e59e
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ github.com/gorse-io/clickhouse v0.3.3-0.20220715124633-688011a495bb h1:z/oOWE+Vy
github.com/gorse-io/clickhouse v0.3.3-0.20220715124633-688011a495bb/go.mod h1:iILWzbul8U+gsf4kqbheF2QzBmdvVp63mloGGK8emDI=
github.com/gorse-io/dashboard v0.0.0-20230224155550-e75876b93f90 h1:fw15FnjCLaxNTv2TM/Jq9qOw2GdZOVL98VY8NmYldPY=
github.com/gorse-io/dashboard v0.0.0-20230224155550-e75876b93f90/go.mod h1:w74IGf70uM5ZCeXmkBhLl3Ux6D+HpBryzcc75VfZA4s=
github.com/gorse-io/oracle v1.2.2-0.20220717033501-725373bd8ae8 h1:hwQjR564WeIVqJyMtXeYS0VwU/UvQl5P3kovpwOmPQQ=
github.com/gorse-io/oracle v1.2.2-0.20220717033501-725373bd8ae8/go.mod h1:Sjtk+MzBxCY6rb2X7Eg3NFiRMGFPug46WocXPg6s1VQ=
github.com/gorse-io/sqlite v1.3.3-0.20220713123255-c322aec4e59e h1:uPQtYQzG1QcC3Qbv+tuEe8Q2l++V4KEcqYSSwB9qobg=
github.com/gorse-io/sqlite v1.3.3-0.20220713123255-c322aec4e59e/go.mod h1:PmIOwYnI+F1lRKd6F/PdLXGgI8GZ5H8x8z1yx0+0bmQ=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
Expand Down
16 changes: 0 additions & 16 deletions storage/cache/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/XSAM/otelsql"
"github.com/araddon/dateparse"
"github.com/dzwvip/oracle"
"github.com/go-redis/redis/extra/redisotel/v9"
"github.com/go-redis/redis/v9"
"github.com/juju/errors"
Expand Down Expand Up @@ -419,21 +418,6 @@ func Open(path, tablePrefix string) (Database, error) {
return nil, errors.Trace(err)
}
return database, nil
} else if strings.HasPrefix(path, storage.OraclePrefix) {
database := new(SQLDatabase)
database.driver = Oracle
database.TablePrefix = storage.TablePrefix(tablePrefix)
if database.client, err = otelsql.Open("oracle", path,
otelsql.WithAttributes(semconv.DBSystemOracle),
otelsql.WithSpanOptions(otelsql.SpanOptions{DisableErrSkip: true}),
); err != nil {
return nil, errors.Trace(err)
}
database.gormDB, err = gorm.Open(oracle.New(oracle.Config{Conn: database.client}), storage.NewGORMConfig(tablePrefix))
if err != nil {
return nil, errors.Trace(err)
}
return database, nil
}
return nil, errors.Errorf("Unknown database: %s", path)
}
1 change: 0 additions & 1 deletion storage/cache/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const (
MySQL SQLDriver = iota
Postgres
SQLite
Oracle
)

type SQLValue struct {
Expand Down
42 changes: 0 additions & 42 deletions storage/cache/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cache
import (
"database/sql"
"fmt"
"net/url"
"os"
"strings"
"testing"
Expand All @@ -30,7 +29,6 @@ import (
var (
mySqlDSN string
postgresDSN string
oracleDSN string
)

func init() {
Expand All @@ -43,7 +41,6 @@ func init() {
}
mySqlDSN = env("MYSQL_URI", "mysql://root:password@tcp(127.0.0.1:3306)/")
postgresDSN = env("POSTGRES_URI", "postgres://gorse:[email protected]/")
oracleDSN = env("ORACLE_URI", "oracle://system:[email protected]:1521/XE")
}

type PostgresTestSuite struct {
Expand Down Expand Up @@ -111,45 +108,6 @@ func TestMySQL(t *testing.T) {
suite.Run(t, new(MySQLTestSuite))
}

type OracleTestSuite struct {
baseTestSuite
}

func (suite *OracleTestSuite) SetupSuite() {
var err error
// create database
databaseComm, err := sql.Open("oracle", oracleDSN)
suite.NoError(err)
const dbName = "GORSE_CACHE_TEST"
rows, err := databaseComm.Query("select * from dba_users where username=:1", dbName)
suite.NoError(err)
if rows.Next() {
// drop user if exists
_, err = databaseComm.Exec(fmt.Sprintf("DROP USER %s CASCADE", dbName))
suite.NoError(err)
}
err = rows.Close()
suite.NoError(err)
_, err = databaseComm.Exec(fmt.Sprintf("CREATE USER %s IDENTIFIED BY %s", dbName, dbName))
suite.NoError(err)
_, err = databaseComm.Exec(fmt.Sprintf("GRANT ALL PRIVILEGES TO %s", dbName))
suite.NoError(err)
err = databaseComm.Close()
suite.NoError(err)
// connect database
parsed, err := url.Parse(oracleDSN)
suite.NoError(err)
suite.Database, err = Open(fmt.Sprintf("oracle://%s:%s@%s/%s", dbName, dbName, parsed.Host, parsed.Path), "gorse_")
suite.NoError(err)
// create schema
err = suite.Database.Init()
suite.NoError(err)
}

func TestOracle(t *testing.T) {
suite.Run(t, new(OracleTestSuite))
}

type SQLiteTestSuite struct {
baseTestSuite
}
Expand Down
16 changes: 0 additions & 16 deletions storage/data/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/XSAM/otelsql"
"github.com/dzwvip/oracle"
"github.com/go-redis/redis/v9"
"github.com/juju/errors"
"github.com/samber/lo"
Expand Down Expand Up @@ -275,21 +274,6 @@ func Open(path, tablePrefix string) (Database, error) {
}
log.Logger().Warn("redis is used for testing only")
return database, nil
} else if strings.HasPrefix(path, storage.OraclePrefix) {
database := new(SQLDatabase)
database.driver = Oracle
database.TablePrefix = storage.TablePrefix(tablePrefix)
if database.client, err = otelsql.Open("oracle", path,
otelsql.WithAttributes(semconv.DBSystemOracle),
otelsql.WithSpanOptions(otelsql.SpanOptions{DisableErrSkip: true}),
); err != nil {
return nil, errors.Trace(err)
}
database.gormDB, err = gorm.Open(oracle.New(oracle.Config{Conn: database.client}), storage.NewGORMConfig(tablePrefix))
if err != nil {
return nil, errors.Trace(err)
}
return database, nil
}
return nil, errors.Errorf("Unknown database: %s", path)
}
2 changes: 1 addition & 1 deletion storage/data/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func (suite *baseTestSuite) TestTimezone() {
item, err = suite.Database.GetItem(ctx, "200")
suite.NoError(err)
suite.Equal(now.Round(time.Microsecond).In(time.UTC), item.Timestamp)
case ClickHouse, Oracle:
case ClickHouse:
item, err := suite.Database.GetItem(ctx, "100")
suite.NoError(err)
suite.Equal(now.Truncate(time.Second).In(time.UTC), item.Timestamp)
Expand Down
47 changes: 5 additions & 42 deletions storage/data/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
Postgres
ClickHouse
SQLite
Oracle
)

type SQLItem struct {
Expand Down Expand Up @@ -220,33 +219,6 @@ func (d *SQLDatabase) Init() error {
if err != nil {
return errors.Trace(err)
}
case Oracle:
// create tables
type Items struct {
ItemId string `gorm:"column:ITEM_ID;type:varchar2(256);not null;primaryKey"`
IsHidden bool `gorm:"column:IS_HIDDEN;type:bool;not null"`
Categories []string `gorm:"column:CATEGORIES;type:varchar2(4000);not null"`
Timestamp time.Time `gorm:"column:TIME_STAMP;type:TIMESTAMP;not null"`
Labels []string `gorm:"column:LABELS;type:varchar2(4000);not null"`
Comment string `gorm:"column:\"COMMENT\";type:varchar2(4000)"`
}
type Users struct {
UserId string `gorm:"column:USER_ID;type:varchar2(256);not null;primaryKey"`
Labels []string `gorm:"column:LABELS;type:varchar2(4000);not null"`
Subscribe []string `gorm:"column:SUBSCRIBE;type:varchar2(4000);not null"`
Comment string `gorm:"column:\"COMMENT\";type:varchar2(4000)"`
}
type Feedback struct {
FeedbackType string `gorm:"column:FEEDBACK_TYPE;type:varchar2(256);not null;primaryKey"`
UserId string `gorm:"column:USER_ID;type:varchar2(256);not null;primaryKey;index:user_id_index"`
ItemId string `gorm:"column:ITEM_ID;type:varchar2(256);not null;primaryKey;index:item_id_index"`
Timestamp time.Time `gorm:"column:TIME_STAMP;type:TIMESTAMP;not null"`
Comment string `gorm:"column:\"COMMENT\";type:varchar2(4000)"`
}
err := d.gormDB.AutoMigrate(Users{}, Items{}, Feedback{})
if err != nil {
return errors.Trace(err)
}
case ClickHouse:
// create tables
type Items struct {
Expand Down Expand Up @@ -341,7 +313,7 @@ func (d *SQLDatabase) BatchInsertItems(ctx context.Context, items []Item) error
if !memo.Has(item.ItemId) {
memo.Add(item.ItemId)
row := NewSQLItem(item)
if d.driver == SQLite || d.driver == Oracle {
if d.driver == SQLite {
row.Timestamp = row.Timestamp.In(time.UTC)
}
rows = append(rows, row)
Expand Down Expand Up @@ -451,7 +423,7 @@ func (d *SQLDatabase) ModifyItem(ctx context.Context, itemId string, patch ItemP
}
if patch.Timestamp != nil {
switch d.driver {
case ClickHouse, SQLite, Oracle:
case ClickHouse, SQLite:
attributes["time_stamp"] = patch.Timestamp.In(time.UTC)
default:
attributes["time_stamp"] = patch.Timestamp
Expand Down Expand Up @@ -558,8 +530,6 @@ func (d *SQLDatabase) GetItemFeedback(ctx context.Context, itemId string, feedba
switch d.driver {
case SQLite:
tx.Where("time_stamp <= DATETIME() AND item_id = ?", itemId)
case Oracle:
tx.Where("time_stamp <= SYS_EXTRACT_UTC(SYSTIMESTAMP) AND item_id = ?", itemId)
default:
tx.Where("time_stamp <= NOW() AND item_id = ?", itemId)
}
Expand Down Expand Up @@ -924,7 +894,7 @@ func (d *SQLDatabase) BatchInsertFeedback(ctx context.Context, feedback []Feedba
if users.Has(f.UserId) && items.Has(f.ItemId) {
if _, exist := memo[lo.Tuple3[string, string, string]{f.FeedbackType, f.UserId, f.ItemId}]; !exist {
memo[lo.Tuple3[string, string, string]{f.FeedbackType, f.UserId, f.ItemId}] = struct{}{}
if d.driver == SQLite || d.driver == Oracle {
if d.driver == SQLite {
f.Timestamp = f.Timestamp.In(time.UTC)
}
rows = append(rows, f)
Expand Down Expand Up @@ -955,14 +925,7 @@ func (d *SQLDatabase) GetFeedback(ctx context.Context, cursor string, n int, beg
if err := json.Unmarshal(buf, &cursorKey); err != nil {
return "", nil, err
}
if d.driver == Oracle {
tx.Where("feedback_type > ? OR feedback_type = ? AND user_id > ? OR feedback_type = ? AND user_id = ? AND item_id >= ?",
cursorKey.FeedbackType,
cursorKey.FeedbackType, cursorKey.UserId,
cursorKey.FeedbackType, cursorKey.UserId, cursorKey.ItemId)
} else {
tx.Where("(feedback_type, user_id, item_id) >= (?,?,?)", cursorKey.FeedbackType, cursorKey.UserId, cursorKey.ItemId)
}
tx.Where("(feedback_type, user_id, item_id) >= (?,?,?)", cursorKey.FeedbackType, cursorKey.UserId, cursorKey.ItemId)
}
if len(feedbackTypes) > 0 {
tx.Where("feedback_type IN ?", feedbackTypes)
Expand Down Expand Up @@ -1092,7 +1055,7 @@ func (d *SQLDatabase) DeleteUserItemFeedback(ctx context.Context, userId, itemId

func (d *SQLDatabase) convertTimeZone(timestamp *time.Time) time.Time {
switch d.driver {
case ClickHouse, SQLite, Oracle:
case ClickHouse, SQLite:
return timestamp.In(time.UTC)
default:
return *timestamp
Expand Down
42 changes: 0 additions & 42 deletions storage/data/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package data
import (
"database/sql"
"fmt"
"net/url"
"os"
"strings"
"testing"
Expand All @@ -31,7 +30,6 @@ var (
mySqlDSN string
postgresDSN string
clickhouseDSN string
oracleDSN string
)

func init() {
Expand All @@ -45,7 +43,6 @@ func init() {
mySqlDSN = env("MYSQL_URI", "mysql://root:password@tcp(127.0.0.1:3306)/")
postgresDSN = env("POSTGRES_URI", "postgres://gorse:[email protected]/")
clickhouseDSN = env("CLICKHOUSE_URI", "clickhouse://127.0.0.1:8123/")
oracleDSN = env("ORACLE_URI", "oracle://system:[email protected]:1521/XE")
}

type MySQLTestSuite struct {
Expand Down Expand Up @@ -139,45 +136,6 @@ func TestClickHouse(t *testing.T) {
suite.Run(t, new(ClickHouseTestSuite))
}

type OracleTestSuite struct {
baseTestSuite
}

func (suite *OracleTestSuite) SetupSuite() {
var err error
// create database
databaseComm, err := sql.Open("oracle", oracleDSN)
suite.NoError(err)
const dbName = "GORSE_DATA_TEST"
rows, err := databaseComm.Query("select * from dba_users where username=:1", dbName)
suite.NoError(err)
if rows.Next() {
// drop user if exists
_, err = databaseComm.Exec(fmt.Sprintf("DROP USER %s CASCADE", dbName))
suite.NoError(err)
}
err = rows.Close()
suite.NoError(err)
_, err = databaseComm.Exec(fmt.Sprintf("CREATE USER %s IDENTIFIED BY %s", dbName, dbName))
suite.NoError(err)
_, err = databaseComm.Exec(fmt.Sprintf("GRANT ALL PRIVILEGES TO %s", dbName))
suite.NoError(err)
err = databaseComm.Close()
suite.NoError(err)
// connect database
parsed, err := url.Parse(oracleDSN)
suite.NoError(err)
suite.Database, err = Open(fmt.Sprintf("oracle://%s:%s@%s/%s", dbName, dbName, parsed.Host, parsed.Path), "gorse_")
suite.NoError(err)
// create schema
err = suite.Database.Init()
suite.NoError(err)
}

func TestOracle(t *testing.T) {
suite.Run(t, new(OracleTestSuite))
}

type SQLiteTestSuite struct {
baseTestSuite
}
Expand Down
7 changes: 0 additions & 7 deletions storage/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,3 @@ services:
image: yandex/clickhouse-server:21.10
ports:
- 8123:8123

oracle:
image: gvenzl/oracle-xe:18
ports:
- 1521:1521
environment:
ORACLE_PASSWORD: password
1 change: 0 additions & 1 deletion storage/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (
RedisPrefix = "redis://"
RedissPrefix = "rediss://"
RedisClusterPrefix = "redis+cluster://"
OraclePrefix = "oracle://"
)

func AppendURLParams(rawURL string, params []lo.Tuple2[string, string]) (string, error) {
Expand Down