mirror of
https://github.com/documize/community.git
synced 2025-07-19 21:29:42 +02:00
Enable Full-text Search when using SQL Server 2016+
This commit is contained in:
parent
0524a0c74c
commit
5004e5a85e
10 changed files with 1360 additions and 1199 deletions
|
@ -77,35 +77,42 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
|
|||
runtime.Log.Info(fmt.Sprintf("Database: legacy schema has %d scripts to process", len(toProcess)))
|
||||
}
|
||||
|
||||
tx, err := runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = runScripts(runtime, tx, toProcess)
|
||||
err = runScripts(runtime, toProcess)
|
||||
if err != nil {
|
||||
runtime.Log.Error("Database: error processing SQL scripts", err)
|
||||
tx.Rollback()
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run SQL scripts to instal or upgrade this database.
|
||||
func runScripts(runtime *env.Runtime, tx *sqlx.Tx, scripts []Script) (err error) {
|
||||
// We do not use transactions for Microsoft SQL Server because
|
||||
// CREATE FULLTEXT CATALOG statement cannot be used inside a user transaction.
|
||||
func runScripts(runtime *env.Runtime, scripts []Script) (err error) {
|
||||
tx, err := runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// We can have multiple scripts as each Documize database change has it's own SQL script.
|
||||
for _, script := range scripts {
|
||||
runtime.Log.Info(fmt.Sprintf("Database: processing SQL script %d", script.Version))
|
||||
|
||||
err = executeSQL(tx, runtime.StoreProvider.Type(), runtime.StoreProvider.TypeVariant(), script.Script)
|
||||
err = executeSQL(tx, runtime, script.Script)
|
||||
if err != nil {
|
||||
runtime.Log.Error(fmt.Sprintf("error executing SQL script %d", script.Version), err)
|
||||
if runtime.StoreProvider.Type() != env.StoreTypeSQLServer {
|
||||
tx.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Record the fact we have processed this database script version.
|
||||
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version))
|
||||
if runtime.StoreProvider.Type() != env.StoreTypeSQLServer {
|
||||
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version))
|
||||
} else {
|
||||
_, err = runtime.Db.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version))
|
||||
}
|
||||
if err != nil {
|
||||
// For MySQL we try the legacy DB schema.
|
||||
if runtime.StoreProvider.Type() == env.StoreTypeMySQL {
|
||||
|
@ -114,31 +121,45 @@ func runScripts(runtime *env.Runtime, tx *sqlx.Tx, scripts []Script) (err error)
|
|||
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgradeLegacy(script.Version))
|
||||
if err != nil {
|
||||
runtime.Log.Error(fmt.Sprintf("error recording execution of SQL script %d", script.Version), err)
|
||||
if runtime.StoreProvider.Type() != env.StoreTypeSQLServer {
|
||||
tx.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Unknown issue running script on non-MySQL database.
|
||||
runtime.Log.Error(fmt.Sprintf("error executing SQL script %d", script.Version), err)
|
||||
if runtime.StoreProvider.Type() != env.StoreTypeSQLServer {
|
||||
tx.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// executeSQL runs specified SQL commands.
|
||||
func executeSQL(tx *sqlx.Tx, st env.StoreType, variant env.StoreType, SQLfile []byte) error {
|
||||
func executeSQL(tx *sqlx.Tx, runtime *env.Runtime, SQLfile []byte) error {
|
||||
// Turn SQL file contents into runnable SQL statements.
|
||||
stmts := getStatements(SQLfile)
|
||||
|
||||
for _, stmt := range stmts {
|
||||
// MariaDB has no specific JSON column type (but has JSON queries)
|
||||
if st == env.StoreTypeMySQL && variant == env.StoreTypeMariaDB {
|
||||
if runtime.StoreProvider.Type() == env.StoreTypeMySQL &&
|
||||
runtime.StoreProvider.TypeVariant() == env.StoreTypeMariaDB {
|
||||
stmt = strings.Replace(stmt, "` JSON", "` TEXT", -1)
|
||||
}
|
||||
|
||||
_, err := tx.Exec(stmt)
|
||||
var err error
|
||||
if runtime.StoreProvider.Type() != env.StoreTypeSQLServer {
|
||||
_, err = tx.Exec(stmt)
|
||||
} else {
|
||||
_, err = runtime.Db.Exec(stmt)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("sql statement error:", stmt)
|
||||
return err
|
||||
|
|
16
core/database/scripts/sqlserver/db_00004.sql
Normal file
16
core/database/scripts/sqlserver/db_00004.sql
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* Enterprise edition */
|
||||
|
||||
-- Fulltext search support
|
||||
IF EXISTS (SELECT * FROM sysfulltextcatalogs ftc WHERE ftc.name = N'dmz_search_catalog')
|
||||
DROP FULLTEXT CATALOG dmz_search_catalog;
|
||||
|
||||
CREATE FULLTEXT CATALOG dmz_search_catalog;
|
||||
|
||||
CREATE UNIQUE INDEX idx_doc_4 ON dmz_doc(c_refid);
|
||||
CREATE UNIQUE INDEX idx_section_4 ON dmz_section(c_refid);
|
||||
|
||||
CREATE FULLTEXT INDEX ON dmz_doc (c_name, c_desc) KEY INDEX idx_doc_4 ON dmz_search_catalog
|
||||
WITH CHANGE_TRACKING AUTO;
|
||||
|
||||
CREATE FULLTEXT INDEX ON dmz_section (c_name, c_body) KEY INDEX idx_section_4 ON dmz_search_catalog
|
||||
WITH CHANGE_TRACKING AUTO;
|
Loading…
Add table
Add a link
Reference in a new issue