mirror of
https://github.com/documize/community.git
synced 2025-07-18 20:59:43 +02:00
WIP SQL Server support
This commit is contained in:
parent
64403c402b
commit
a41f43c380
9 changed files with 804 additions and 749 deletions
|
@ -109,7 +109,7 @@ CREATE TABLE dmz_doc_attachment (
|
|||
c_job NVARCHAR(36) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_fileid NVARCHAR(10) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_filename NVARCHAR(255) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_data VARBINARY(max),
|
||||
c_data VARBINARY(MAX),
|
||||
c_extension NVARCHAR(6) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_created DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
c_revised DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
|
@ -220,7 +220,7 @@ CREATE TABLE dmz_org (
|
|||
c_maxtags INT NOT NULL DEFAULT '3',
|
||||
c_sub NVARCHAR(MAX) NULL,
|
||||
c_theme NVARCHAR(20) NOT NULL DEFAULT '',
|
||||
c_logo VARBINARY(max),
|
||||
c_logo VARBINARY(MAX),
|
||||
c_verified BIT NOT NULL DEFAULT '0',
|
||||
c_serial NVARCHAR(50) COLLATE Latin1_General_CS_AS NOT NULL DEFAULT '',
|
||||
c_active BIT NOT NULL DEFAULT '1',
|
||||
|
@ -309,7 +309,7 @@ CREATE TABLE dmz_section_meta (
|
|||
c_orgid NVARCHAR(20) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_userid NVARCHAR(20) COLLATE Latin1_General_CS_AS NOT NULL DEFAULT '',
|
||||
c_docid NVARCHAR(20) COLLATE Latin1_General_CS_AS NOT NULL,
|
||||
c_rawbody VARBINARY(max),
|
||||
c_rawbody NVARCHAR(MAX),
|
||||
c_config NVARCHAR(MAX) DEFAULT NULL,
|
||||
c_external BIT DEFAULT '0',
|
||||
c_created DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -333,7 +333,7 @@ CREATE TABLE dmz_section_revision (
|
|||
c_type NVARCHAR(10) COLLATE Latin1_General_CS_AS NOT NULL DEFAULT 'section',
|
||||
c_name NVARCHAR(2000) COLLATE Latin1_General_CS_AS NOT NULL DEFAULT '',
|
||||
c_body NVARCHAR(MAX) COLLATE Latin1_General_CS_AS,
|
||||
c_rawbody VARBINARY(max),
|
||||
c_rawbody NVARCHAR(MAX),
|
||||
c_config NVARCHAR(MAX) DEFAULT NULL,
|
||||
c_created DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
c_revised DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
|
@ -356,7 +356,7 @@ CREATE TABLE dmz_section_template (
|
|||
c_body NVARCHAR(MAX) COLLATE Latin1_General_CS_AS,
|
||||
c_desc NVARCHAR(2000) COLLATE Latin1_General_CS_AS NOT NULL DEFAULT '',
|
||||
c_used INT NOT NULL,
|
||||
c_rawbody VARBINARY(max),
|
||||
c_rawbody NVARCHAR(MAX),
|
||||
c_config NVARCHAR(MAX) DEFAULT NULL,
|
||||
c_external BIT DEFAULT '0',
|
||||
c_created DATETIME2 NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
|
|
@ -239,13 +239,13 @@ func (s Store) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string
|
|||
GROUP BY c_groupid
|
||||
) AS x INNER JOIN dmz_doc AS d ON d.c_groupid=x.c_groupid AND d.c_versionorder=x.latestversion
|
||||
)
|
||||
GROUP BY c_categoryid, grouptype
|
||||
GROUP BY c_categoryid
|
||||
UNION ALL
|
||||
SELECT 'users' AS grouptype, c_refid AS categoryid, count(*) AS count
|
||||
FROM dmz_permission
|
||||
WHERE c_orgid=? AND c_location='category' AND c_refid IN
|
||||
(SELECT c_refid FROM dmz_category WHERE c_orgid=? AND c_spaceid=?)
|
||||
GROUP BY c_refid, grouptype`),
|
||||
GROUP BY c_refid`),
|
||||
ctx.OrgID, spaceID,
|
||||
ctx.OrgID, spaceID, ctx.OrgID, spaceID,
|
||||
ctx.OrgID, ctx.OrgID, spaceID)
|
||||
|
|
|
@ -61,10 +61,12 @@ func (s Store) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
|||
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_section (c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_name, c_body, c_revisions, c_sequence, c_templateid, c_status, c_relativeid, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.Type, model.Page.Level, model.Page.Name, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.TemplateID, model.Page.Status, model.Page.RelativeID, model.Page.Created, model.Page.Revised)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute page insert")
|
||||
}
|
||||
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_section_meta (c_sectionid, c_orgid, c_userid, c_docid, c_rawbody, c_config, c_external, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
model.Meta.SectionID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute page meta insert")
|
||||
}
|
||||
|
@ -241,7 +243,7 @@ func (s Store) GetPageMeta(ctx domain.RequestContext, pageID string) (meta page.
|
|||
c_orgid AS orgid, c_userid AS userid, c_docid AS documentid,
|
||||
c_rawbody AS rawbody, coalesce(c_config,`+s.EmptyJSON()+`) as config,
|
||||
c_external AS externalsource, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section_meta
|
||||
FROM dmz_section_meta
|
||||
WHERE c_orgid=? AND c_sectionid=?`),
|
||||
ctx.OrgID, pageID)
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ package search
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/model/attachment"
|
||||
"github.com/documize/community/model/category"
|
||||
|
@ -25,6 +27,10 @@ import (
|
|||
// IndexDocument adds search indesd entries for document inserting title, tags and attachments as
|
||||
// searchable items. Any existing document entries are removed.
|
||||
func (m *Indexer) IndexDocument(ctx domain.RequestContext, d doc.Document, a []attachment.Attachment) {
|
||||
if m.runtime.StoreProvider.Type() == env.StoreTypeSQLServer {
|
||||
return
|
||||
}
|
||||
|
||||
method := "search.IndexDocument"
|
||||
var err error
|
||||
|
||||
|
@ -47,6 +53,10 @@ func (m *Indexer) IndexDocument(ctx domain.RequestContext, d doc.Document, a []a
|
|||
|
||||
// DeleteDocument removes all search entries for document.
|
||||
func (m *Indexer) DeleteDocument(ctx domain.RequestContext, ID string) {
|
||||
if m.runtime.StoreProvider.Type() == env.StoreTypeSQLServer {
|
||||
return
|
||||
}
|
||||
|
||||
method := "search.DeleteDocument"
|
||||
var err error
|
||||
|
||||
|
@ -70,6 +80,10 @@ func (m *Indexer) DeleteDocument(ctx domain.RequestContext, ID string) {
|
|||
// IndexContent adds search index entry for document context.
|
||||
// Any existing document entries are removed.
|
||||
func (m *Indexer) IndexContent(ctx domain.RequestContext, p page.Page) {
|
||||
if m.runtime.StoreProvider.Type() == env.StoreTypeSQLServer {
|
||||
return
|
||||
}
|
||||
|
||||
method := "search.IndexContent"
|
||||
var err error
|
||||
|
||||
|
@ -97,6 +111,10 @@ func (m *Indexer) IndexContent(ctx domain.RequestContext, p page.Page) {
|
|||
|
||||
// DeleteContent removes all search entries for specific document content.
|
||||
func (m *Indexer) DeleteContent(ctx domain.RequestContext, pageID string) {
|
||||
if m.runtime.StoreProvider.Type() == env.StoreTypeSQLServer {
|
||||
return
|
||||
}
|
||||
|
||||
method := "search.DeleteContent"
|
||||
var err error
|
||||
|
||||
|
|
|
@ -15,10 +15,11 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/documize/community/model/category"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/model/category"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/event"
|
||||
"github.com/documize/community/core/request"
|
||||
|
@ -36,6 +37,7 @@ import (
|
|||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/page"
|
||||
pm "github.com/documize/community/model/permission"
|
||||
|
||||
// "github.com/documize/community/model/template"
|
||||
"github.com/documize/community/model/workflow"
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
|
@ -336,12 +338,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
ctx.Transaction, _ = h.Runtime.StartTx(sql.LevelReadUncommitted)
|
||||
|
||||
// Prepare new document
|
||||
documentID = uniqueid.Generate()
|
||||
|
@ -386,11 +383,10 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
model.Meta = meta
|
||||
|
||||
err = h.Store.Page.Add(ctx, model)
|
||||
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func InitRuntime(r *env.Runtime, s *store.Store) bool {
|
|||
}
|
||||
|
||||
// Open connection to database
|
||||
db, err := sqlx.Open(r.StoreProvider.DriverName(), r.StoreProvider.MakeConnectionString()) //r.Flags.DBConn
|
||||
db, err := sqlx.Open(r.StoreProvider.DriverName(), r.StoreProvider.MakeConnectionString())
|
||||
if err != nil {
|
||||
r.Log.Error("Unable to open database", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -185,7 +185,13 @@ func (p SQLServerProvider) DriverName() string {
|
|||
// Params returns connection string parameters that must be present before connecting to DB.
|
||||
func (p SQLServerProvider) Params() map[string]string {
|
||||
// Not used for this provider.
|
||||
return map[string]string{}
|
||||
// return map[string]string{}
|
||||
|
||||
return map[string]string{
|
||||
"app+name": "Documize",
|
||||
"connection+timeout": "0",
|
||||
"keep-alive": "0",
|
||||
}
|
||||
}
|
||||
|
||||
// Example holds storage provider specific connection string format
|
||||
|
@ -217,8 +223,42 @@ func (p SQLServerProvider) DatabaseName() string {
|
|||
// MakeConnectionString returns provider specific DB connection string
|
||||
// complete with default parameters.
|
||||
func (p SQLServerProvider) MakeConnectionString() string {
|
||||
queryBits := strings.Split(p.ConnectionString, "?")
|
||||
ret := queryBits[0] + "?"
|
||||
retFirst := true
|
||||
|
||||
params := p.Params()
|
||||
|
||||
if len(queryBits) == 2 {
|
||||
paramBits := strings.Split(queryBits[1], "&")
|
||||
for _, pb := range paramBits {
|
||||
found := false
|
||||
if assignBits := strings.Split(pb, "="); len(assignBits) == 2 {
|
||||
_, found = params[strings.TrimSpace(assignBits[0])]
|
||||
}
|
||||
if !found { // if we can't work out what it is, put it through
|
||||
if retFirst {
|
||||
retFirst = false
|
||||
} else {
|
||||
ret += "&"
|
||||
}
|
||||
ret += pb
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range params {
|
||||
if retFirst {
|
||||
retFirst = false
|
||||
} else {
|
||||
ret += "&"
|
||||
}
|
||||
ret += k + "=" + v
|
||||
}
|
||||
|
||||
return ret
|
||||
// No special processing so return as-is.
|
||||
return p.ConnectionString
|
||||
// return p.ConnectionString
|
||||
}
|
||||
|
||||
// QueryMeta is how to extract version number, version related comment,
|
||||
|
|
1454
embed/bindata.go
1454
embed/bindata.go
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,6 @@
|
|||
{{#attach-popover class="ember-attacher-popper" hideOn="clickout" showOn="click" isShown=false}}
|
||||
<ul class="menu">
|
||||
<li class="item" {{action "onExport"}}>Export as HTML file</li>
|
||||
<li class="item" {{action "onPDF"}}>Download as PDF</li>
|
||||
<li class="item" {{action "onPrintDocument"}}>Print...</li>
|
||||
</ul>
|
||||
{{/attach-popover}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue