/Raven.Database/Storage/Esent/SchemaUpdates/Updates/From37To38.cs
https://github.com/samueldjack/ravendb · C# · 282 lines · 242 code · 35 blank · 5 comment · 0 complexity · b4933ad23d80831e582b7ff769c2600f MD5 · raw file
- // -----------------------------------------------------------------------
- // <copyright file="From37To38.cs" company="Hibernating Rhinos LTD">
- // Copyright (c) Hibernating Rhinos LTD. All rights reserved.
- // </copyright>
- // -----------------------------------------------------------------------
- using Microsoft.Isam.Esent.Interop;
- using Raven.Database.Impl;
-
- namespace Raven.Storage.Esent.SchemaUpdates.Updates
- {
- public class From37To38 : ISchemaUpdate
- {
- public string FromSchemaVersion { get { return "3.7"; } }
-
- public void Init(IUuidGenerator generator)
- {
- }
-
- public void Update(Session session, JET_DBID dbid)
- {
- Api.JetDeleteTable(session, dbid, "mapped_results"); // just kill the old table, we won't use the data anyway
- CreateMapResultsTable(session, dbid);
- CreateReduceResultsTable(session, dbid);
- CreateScheduledReductionsTable(session, dbid);
- SchemaCreator.UpdateVersion(session, dbid, "3.8");
- }
-
-
- private void CreateScheduledReductionsTable(Session session, JET_DBID dbid)
- {
- JET_TABLEID tableid;
- Api.JetCreateTable(session, dbid, "scheduled_reductions", 1, 80, out tableid);
- JET_COLUMNID columnid;
-
- Api.JetAddColumn(session, tableid, "id", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "view", new JET_COLUMNDEF
- {
- cbMax = 2048,
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "reduce_key", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "etag", new JET_COLUMNDEF
- {
- cbMax = 16,
- coltyp = JET_coltyp.Binary,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "timestamp", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.DateTime,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "bucket", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "level", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- SchemaCreator.CreateIndexes(session, tableid,
- new JET_INDEXCREATE
- {
- szIndexName = "by_id",
- szKey = "+id\0\0",
- grbit = CreateIndexGrbit.IndexPrimary
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view",
- szKey = "+view\0\0",
- grbit = CreateIndexGrbit.IndexDisallowNull
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_level_reduce_key_and_bucket",
- szKey = "+view\0+level\0+reduce_key\0+bucket\0\0",
- });
- }
-
- private void CreateMapResultsTable(Session session, JET_DBID dbid)
- {
- JET_TABLEID tableid;
- Api.JetCreateTable(session, dbid, "mapped_results", 1, 80, out tableid);
- JET_COLUMNID columnid;
-
- Api.JetAddColumn(session, tableid, "id", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "view", new JET_COLUMNDEF
- {
- cbMax = 2048,
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "document_key", new JET_COLUMNDEF
- {
- cbMax = 2048,
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "reduce_key", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "data", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.LongBinary,
- grbit = ColumndefGrbit.ColumnTagged
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "etag", new JET_COLUMNDEF
- {
- cbMax = 16,
- coltyp = JET_coltyp.Binary,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "timestamp", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.DateTime,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "bucket", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- SchemaCreator.CreateIndexes(session, tableid,
- new JET_INDEXCREATE
- {
- szIndexName = "by_id",
- szKey = "+id\0\0",
- grbit = CreateIndexGrbit.IndexPrimary
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_and_doc_key",
- szKey = "+view\0+document_key\0\0",
- grbit = CreateIndexGrbit.IndexDisallowNull
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view",
- szKey = "+view\0\0",
- grbit = CreateIndexGrbit.IndexDisallowNull
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_and_etag",
- szKey = "+view\0-etag\0\0",
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_reduce_key_and_bucket",
- szKey = "+view\0+reduce_key\0+bucket\0\0",
- });
- }
-
- private void CreateReduceResultsTable(Session session, JET_DBID dbid)
- {
- JET_TABLEID tableid;
- Api.JetCreateTable(session, dbid, "reduce_results", 1, 80, out tableid);
- JET_COLUMNID columnid;
-
- Api.JetAddColumn(session, tableid, "id", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnAutoincrement | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "view", new JET_COLUMNDEF
- {
- cbMax = 2048,
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "reduce_key", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.LongText,
- cp = JET_CP.Unicode,
- grbit = SchemaCreator.ColumnNotNullIfOnHigherThanWindowsXp()
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "data", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.LongBinary,
- grbit = ColumndefGrbit.ColumnTagged
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "etag", new JET_COLUMNDEF
- {
- cbMax = 16,
- coltyp = JET_coltyp.Binary,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "timestamp", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.DateTime,
- grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "bucket", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "source_bucket", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- Api.JetAddColumn(session, tableid, "level", new JET_COLUMNDEF
- {
- coltyp = JET_coltyp.Long,
- grbit = ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnNotNULL
- }, null, 0, out columnid);
-
- SchemaCreator.CreateIndexes(session, tableid,
- new JET_INDEXCREATE
- {
- szIndexName = "by_id",
- szKey = "+id\0\0",
- grbit = CreateIndexGrbit.IndexPrimary
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view",
- szKey = "+view\0\0",
- grbit = CreateIndexGrbit.IndexDisallowNull
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_level_reduce_key_and_bucket",
- szKey = "+view\0+level\0+reduce_key\0+bucket\0\0",
- },
- new JET_INDEXCREATE
- {
- szIndexName = "by_view_level_reduce_key_and_source_bucket",
- szKey = "+view\0+level\0+reduce_key\0+source_bucket\0\0",
- });
- }
-
- }
- }