@oaknational/oak-curriculum-schema-v2 0.0.7-alpha → 0.0.8-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.cjs +214 -155
- package/cjs/index.cjs.map +1 -1
- package/esm/index.js +214 -155
- package/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/schema/draft-documents-with-status-by-lesson.ts +0 -6
- package/src/schema/draft-lesson-with-status.ts +0 -2
- package/src/schema/published-lesson-video-with-release-by-lesson.ts +2 -4
- package/src/schema/published-lesson-with-release.ts +0 -2
- package/types.d.ts +1729 -2140
package/cjs/index.cjs
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
"use strict";var e=require("zod-to-camel-case"),t=require("drizzle-zod"),i=require("drizzle-orm"),n=require("zod");function s(e){return e&&e.__esModule?e:{default:e}}var o=s(e);const a=Symbol.for("drizzle:entityKind");function r(e,t){if(!e||"object"!=typeof e)return!1;if(e instanceof t)return!0;if(!Object.prototype.hasOwnProperty.call(t,a))throw new Error(`Class "${t.name??"<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let i=Object.getPrototypeOf(e).constructor;if(i)for(;i;){if(a in i&&i[a]===t[a])return!0;i=Object.getPrototypeOf(i)}return!1}class _{constructor(e,t){this.table=e,this.config=t,this.name=t.name,this.keyAsName=t.keyAsName,this.notNull=t.notNull,this.default=t.default,this.defaultFn=t.defaultFn,this.onUpdateFn=t.onUpdateFn,this.hasDefault=t.hasDefault,this.primary=t.primaryKey,this.isUnique=t.isUnique,this.uniqueName=t.uniqueName,this.uniqueType=t.uniqueType,this.dataType=t.dataType,this.columnType=t.columnType,this.generated=t.generated,this.generatedIdentity=t.generatedIdentity}static[a]="Column";name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;config;mapFromDriverValue(e){return e}mapToDriverValue(e){return e}shouldDisableInsert(){return void 0!==this.config.generated&&"byDefault"!==this.config.generated.type}}class l{static[a]="ColumnBuilder";config;constructor(e,t,i){this.config={name:e,keyAsName:""===e,notNull:!1,default:void 0,hasDefault:!1,primaryKey:!1,isUnique:!1,uniqueName:void 0,uniqueType:void 0,dataType:t,columnType:i,generated:void 0}}$type(){return this}notNull(){return this.config.notNull=!0,this}default(e){return this.config.default=e,this.config.hasDefault=!0,this}$defaultFn(e){return this.config.defaultFn=e,this.config.hasDefault=!0,this}$default=this.$defaultFn;$onUpdateFn(e){return this.config.onUpdateFn=e,this.config.hasDefault=!0,this}$onUpdate=this.$onUpdateFn;primaryKey(){return this.config.primaryKey=!0,this.config.notNull=!0,this}setName(e){""===this.config.name&&(this.config.name=e)}}const u=Symbol.for("drizzle:Name");class d{static[a]="PgForeignKeyBuilder";reference;_onUpdate="no action";_onDelete="no action";constructor(e,t){this.reference=()=>{const{name:t,columns:i,foreignColumns:n}=e();return{name:t,columns:i,foreignTable:n[0].table,foreignColumns:n}},t&&(this._onUpdate=t.onUpdate,this._onDelete=t.onDelete)}onUpdate(e){return this._onUpdate=void 0===e?"no action":e,this}onDelete(e){return this._onDelete=void 0===e?"no action":e,this}build(e){return new c(e,this)}}class c{constructor(e,t){this.table=e,this.reference=t.reference,this.onUpdate=t._onUpdate,this.onDelete=t._onDelete}static[a]="PgForeignKey";reference;onUpdate;onDelete;getName(){const{name:e,columns:t,foreignColumns:i}=this.reference(),n=t.map(e=>e.name),s=i.map(e=>e.name),o=[this.table[u],...n,i[0].table[u],...s];return e??`${o.join("_")}_fk`}}function m(e){return new d(function(){const{name:t,columns:i,foreignColumns:n}=e;return{name:t,columns:i,foreignColumns:n}})}function p(e){return new f(e)}function g(e,t){return`${e[u]}_${t.join("_")}_unique`}class h{constructor(e,t){this.name=t,this.columns=e}static[a]="PgUniqueConstraintBuilder";columns;nullsNotDistinctConfig=!1;nullsNotDistinct(){return this.nullsNotDistinctConfig=!0,this}build(e){return new y(e,this.columns,this.nullsNotDistinctConfig,this.name)}}class f{static[a]="PgUniqueOnConstraintBuilder";name;constructor(e){this.name=e}on(...e){return new h(e,this.name)}}class y{constructor(e,t,i,n){this.table=e,this.columns=t,this.name=n??g(this.table,this.columns.map(e=>e.name)),this.nullsNotDistinct=i}static[a]="PgUniqueConstraint";columns;name;nullsNotDistinct=!1;getName(){return this.name}}function b(e,t,i){for(let n=t;n<e.length;n++){const s=e[n];if("\\"!==s){if('"'===s)return[e.slice(t,n).replace(/\\/g,""),n+1];if(!i&&(","===s||"}"===s))return[e.slice(t,n).replace(/\\/g,""),n]}else n++}return[e.slice(t).replace(/\\/g,""),e.length]}function v(e,t=0){const i=[];let n=t,s=!1;for(;n<e.length;){const o=e[n];if(","===o){(s||n===t)&&i.push(""),s=!0,n++;continue}if(s=!1,"\\"===o){n+=2;continue}if('"'===o){const[t,s]=b(e,n+1,!0);i.push(t),n=s;continue}if("}"===o)return[i,n+1];if("{"===o){const[t,s]=v(e,n+1);i.push(t),n=s;continue}const[a,r]=b(e,n,!1);i.push(a),n=r}return[i,n]}function w(e){const[t]=v(e,1);return t}function N(e){return`{${e.map(e=>Array.isArray(e)?N(e):"string"==typeof e?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`${e}`).join(",")}}`}class k extends l{foreignKeyConfigs=[];static[a]="PgColumnBuilder";array(e){return new q(this.config.name,this,e)}references(e,t={}){return this.foreignKeyConfigs.push({ref:e,actions:t}),this}unique(e,t){return this.config.isUnique=!0,this.config.uniqueName=e,this.config.uniqueType=t?.nulls,this}generatedAlwaysAs(e){return this.config.generated={as:e,type:"always",mode:"stored"},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:i,actions:n})=>function(e,...t){return e(...t)}((i,n)=>{const s=new d(()=>{const t=i();return{columns:[e],foreignColumns:[t]}});return n.onUpdate&&s.onUpdate(n.onUpdate),n.onDelete&&s.onDelete(n.onDelete),s.build(t)},i,n))}buildExtraConfigColumn(e){return new x(e,this.config)}}class S extends _{constructor(e,t){t.uniqueName||(t.uniqueName=g(e,[t.name])),super(e,t),this.table=e}static[a]="PgColumn"}class x extends S{static[a]="ExtraConfigColumn";getSQLType(){return this.getSQLType()}indexConfig={order:this.config.order??"asc",nulls:this.config.nulls??"last",opClass:this.config.opClass};defaultConfig={order:"asc",nulls:"last",opClass:void 0};asc(){return this.indexConfig.order="asc",this}desc(){return this.indexConfig.order="desc",this}nullsFirst(){return this.indexConfig.nulls="first",this}nullsLast(){return this.indexConfig.nulls="last",this}op(e){return this.indexConfig.opClass=e,this}}class C{static[a]="IndexedColumn";constructor(e,t,i,n){this.name=e,this.keyAsName=t,this.type=i,this.indexConfig=n}name;keyAsName;type;indexConfig}class q extends k{static[a]="PgArrayBuilder";constructor(e,t,i){super(e,"array","PgArray"),this.config.baseBuilder=t,this.config.size=i}build(e){const t=this.config.baseBuilder.build(e);return new T(e,this.config,t)}}class T extends S{constructor(e,t,i,n){super(e,t),this.baseColumn=i,this.range=n,this.size=t.size}size;static[a]="PgArray";getSQLType(){return`${this.baseColumn.getSQLType()}[${"number"==typeof this.size?this.size:""}]`}mapFromDriverValue(e){return"string"==typeof e&&(e=w(e)),e.map(e=>this.baseColumn.mapFromDriverValue(e))}mapToDriverValue(e,t=!1){const i=e.map(e=>null===e?null:r(this.baseColumn,T)?this.baseColumn.mapToDriverValue(e,!0):this.baseColumn.mapToDriverValue(e));return t?i:N(i)}}class j extends k{static[a]="PgEnumObjectColumnBuilder";constructor(e,t){super(e,"string","PgEnumObjectColumn"),this.config.enum=t}build(e){return new $(e,this.config)}}class $ extends S{static[a]="PgEnumObjectColumn";enum;enumValues=this.config.enum.enumValues;constructor(e,t){super(e,t),this.enum=t.enum}getSQLType(){return this.enum.enumName}}const A=Symbol.for("drizzle:isPgEnum");class P extends k{static[a]="PgEnumColumnBuilder";constructor(e,t){super(e,"string","PgEnumColumn"),this.config.enum=t}build(e){return new B(e,this.config)}}class B extends S{static[a]="PgEnumColumn";enum=this.config.enum;enumValues=this.config.enum.enumValues;constructor(e,t){super(e,t),this.enum=t.enum}getSQLType(){return this.enum.enumName}}class z{static[a]="Subquery";constructor(e,t,i,n=!1,s=[]){this._={brand:"Subquery",sql:e,selectedFields:t,alias:i,isWith:n,usedTables:s}}}class D extends z{static[a]="WithSubquery"}const O={startActiveSpan:(e,t)=>t()},L=Symbol.for("drizzle:ViewBaseConfig"),I=Symbol.for("drizzle:Schema"),F=Symbol.for("drizzle:Columns"),Q=Symbol.for("drizzle:ExtraConfigColumns"),V=Symbol.for("drizzle:OriginalName"),E=Symbol.for("drizzle:BaseName"),K=Symbol.for("drizzle:IsAlias"),U=Symbol.for("drizzle:ExtraConfigBuilder"),J=Symbol.for("drizzle:IsDrizzleTable");class R{static[a]="Table";static Symbol={Name:u,Schema:I,OriginalName:V,Columns:F,ExtraConfigColumns:Q,BaseName:E,IsAlias:K,ExtraConfigBuilder:U};[u];[V];[I];[F];[Q];[E];[K]=!1;[J]=!0;[U]=void 0;constructor(e,t,i){this[u]=this[V]=e,this[I]=t,this[E]=i}}function M(e){return e[u]}function W(e){return`${e[I]??"public"}.${e[u]}`}function H(e){return null!=e&&"function"==typeof e.getSQL}class G{static[a]="StringChunk";value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new Y([this])}}class Y{constructor(e){this.queryChunks=e;for(const t of e)if(r(t,R)){const e=t[R.Symbol.Schema];this.usedTables.push(void 0===e?t[R.Symbol.Name]:e+"."+t[R.Symbol.Name])}}static[a]="SQL";decoder=X;shouldInlineParams=!1;usedTables=[];append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return O.startActiveSpan("drizzle.buildSQL",t=>{const i=this.buildQueryFromSourceParams(this.queryChunks,e);return t?.setAttributes({"drizzle.query.text":i.sql,"drizzle.query.params":JSON.stringify(i.params)}),i})}buildQueryFromSourceParams(e,t){const i=Object.assign({},t,{inlineParams:t.inlineParams||this.shouldInlineParams,paramStartIndex:t.paramStartIndex||{value:0}}),{casing:n,escapeName:s,escapeParam:o,prepareTyping:a,inlineParams:l,paramStartIndex:u}=i;return function(e){const t={sql:"",params:[]};for(const i of e)t.sql+=i.sql,t.params.push(...i.params),i.typings?.length&&(t.typings||(t.typings=[]),t.typings.push(...i.typings));return t}(e.map(e=>{if(r(e,G))return{sql:e.value.join(""),params:[]};if(r(e,Z))return{sql:s(e.value),params:[]};if(void 0===e)return{sql:"",params:[]};if(Array.isArray(e)){const t=[new G("(")];for(const[i,n]of e.entries())t.push(n),i<e.length-1&&t.push(new G(", "));return t.push(new G(")")),this.buildQueryFromSourceParams(t,i)}if(r(e,Y))return this.buildQueryFromSourceParams(e.queryChunks,{...i,inlineParams:l||e.shouldInlineParams});if(r(e,R)){const t=e[R.Symbol.Schema],i=e[R.Symbol.Name];return{sql:void 0===t||e[K]?s(i):s(t)+"."+s(i),params:[]}}if(r(e,_)){const i=n.getColumnCasing(e);if("indexes"===t.invokeSource)return{sql:s(i),params:[]};const o=e.table[R.Symbol.Schema];return{sql:e.table[K]||void 0===o?s(e.table[R.Symbol.Name])+"."+s(i):s(o)+"."+s(e.table[R.Symbol.Name])+"."+s(i),params:[]}}if(r(e,ae)){const t=e[L].schema,i=e[L].name;return{sql:void 0===t||e[L].isAlias?s(i):s(t)+"."+s(i),params:[]}}if(r(e,te)){if(r(e.value,se))return{sql:o(u.value++,e),params:[e],typings:["none"]};const t=null===e.value?null:e.encoder.mapToDriverValue(e.value);if(r(t,Y))return this.buildQueryFromSourceParams([t],i);if(l)return{sql:this.mapInlineParam(t,i),params:[]};let n=["none"];return a&&(n=[a(e.encoder)]),{sql:o(u.value++,t),params:[t],typings:n}}return r(e,se)?{sql:o(u.value++,e),params:[e],typings:["none"]}:r(e,Y.Aliased)&&void 0!==e.fieldAlias?{sql:s(e.fieldAlias),params:[]}:r(e,z)?e._.isWith?{sql:s(e._.alias),params:[]}:this.buildQueryFromSourceParams([new G("("),e._.sql,new G(") "),new Z(e._.alias)],i):(d=e)&&"function"==typeof d&&A in d&&!0===d[A]?e.schema?{sql:s(e.schema)+"."+s(e.enumName),params:[]}:{sql:s(e.enumName),params:[]}:H(e)?e.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([e.getSQL()],i):this.buildQueryFromSourceParams([new G("("),e.getSQL(),new G(")")],i):l?{sql:this.mapInlineParam(e,i),params:[]}:{sql:o(u.value++,e),params:[e],typings:["none"]};var d}))}mapInlineParam(e,{escapeString:t}){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e)return e.toString();if("string"==typeof e)return t(e);if("object"==typeof e){const i=e.toString();return t("[object Object]"===i?JSON.stringify(e):i)}throw new Error("Unexpected param value: "+e)}getSQL(){return this}as(e){return void 0===e?this:new Y.Aliased(this,e)}mapWith(e){return this.decoder="function"==typeof e?{mapFromDriverValue:e}:e,this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}}class Z{constructor(e){this.value=e}static[a]="Name";brand;getSQL(){return new Y([this])}}const X={mapFromDriverValue:e=>e},ee={mapToDriverValue:e=>e};class te{constructor(e,t=ee){this.value=e,this.encoder=t}static[a]="Param";brand;getSQL(){return new Y([this])}}function ie(e,...t){const i=[];(t.length>0||e.length>0&&""!==e[0])&&i.push(new G(e[0]));for(const[n,s]of t.entries())i.push(s,new G(e[n+1]));return new Y(i)}var ne;(ne=ie||(ie={})).empty=function(){return new Y([])},ne.fromList=function(e){return new Y(e)},ne.raw=function(e){return new Y([new G(e)])},ne.join=function(e,t){const i=[];for(const[n,s]of e.entries())n>0&&void 0!==t&&i.push(t),i.push(s);return new Y(i)},ne.identifier=function(e){return new Z(e)},ne.placeholder=function(e){return new se(e)},ne.param=function(e,t){return new te(e,t)},(e=>{class t{constructor(e,t){this.sql=e,this.fieldAlias=t}static[a]="SQL.Aliased";isSelectionField=!1;getSQL(){return this.sql}clone(){return new t(this.sql,this.fieldAlias)}}e.Aliased=t})(Y||(Y={}));class se{constructor(e){this.name=e}static[a]="Placeholder";getSQL(){return new Y([this])}}const oe=Symbol.for("drizzle:IsDrizzleView");class ae{static[a]="View";[L];[oe]=!0;constructor({name:e,schema:t,selectedFields:i,query:n}){this[L]={name:e,originalName:e,schema:t,selectedFields:i,query:n,isExisting:!n,isAlias:!1}}getSQL(){return new Y([this])}}_.prototype.getSQL=function(){return new Y([this])},R.prototype.getSQL=function(){return new Y([this])},z.prototype.getSQL=function(){return new Y([this])};class re{constructor(e){this.table=e}static[a]="ColumnAliasProxyHandler";get(e,t){return"table"===t?this.table:e[t]}}class _e{constructor(e,t){this.alias=e,this.replaceOriginalName=t}static[a]="TableAliasProxyHandler";get(e,t){if(t===R.Symbol.IsAlias)return!0;if(t===R.Symbol.Name)return this.alias;if(this.replaceOriginalName&&t===R.Symbol.OriginalName)return this.alias;if(t===L)return{...e[L],name:this.alias,isAlias:!0};if(t===R.Symbol.Columns){const t=e[R.Symbol.Columns];if(!t)return t;const i={};return Object.keys(t).map(n=>{i[n]=new Proxy(t[n],new re(new Proxy(e,this)))}),i}const i=e[t];return r(i,_)?new Proxy(i,new re(new Proxy(e,this))):i}}function le(e,t){return new Proxy(e,new _e(t,!1))}function ue(e,t){return new Proxy(e,new re(new Proxy(e.table,new _e(t,!1))))}function de(e,t){return new Y.Aliased(ce(e.sql,t),e.fieldAlias)}function ce(e,t){return ie.join(e.queryChunks.map(e=>r(e,_)?ue(e,t):r(e,Y)?ce(e,t):r(e,Y.Aliased)?de(e,t):e))}class me{constructor(e,t){this.name=e,this.value=t}static[a]="PgCheckBuilder";brand;build(e){return new pe(e,this)}}class pe{constructor(e,t){this.table=e,this.name=t.name,this.value=t.value}static[a]="PgCheck";name;value}function ge(e,t){return new me(e,t)}function he(e,t){return Object.entries(e).reduce((e,[i,n])=>{if("string"!=typeof i)return e;const s=t?[...t,i]:[i];return r(n,_)||r(n,Y)||r(n,Y.Aliased)||r(n,z)?e.push({path:s,field:n}):r(n,R)?e.push(...he(n[R.Symbol.Columns],s)):e.push(...he(n,s)),e},[])}function fe(e,t){const i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(const[e,t]of i.entries())if(t!==n[e])return!1;return!0}function ye(e){return e[R.Symbol.Columns]}function be(e){return r(e,z)?e._.alias:r(e,ae)?e[L].name:r(e,Y)?void 0:e[R.Symbol.IsAlias]?e[R.Symbol.Name]:e[R.Symbol.BaseName]}function ve(e,t){return{name:"string"==typeof e&&e.length>0?e:"",config:"object"==typeof e?e:t}}"undefined"!=typeof TextDecoder&&new TextDecoder;class we extends k{static[a]="PgIntColumnBaseBuilder";generatedAlwaysAsIdentity(e){if(e){const{name:t,...i}=e;this.config.generatedIdentity={type:"always",sequenceName:t,sequenceOptions:i}}else this.config.generatedIdentity={type:"always"};return this.config.hasDefault=!0,this.config.notNull=!0,this}generatedByDefaultAsIdentity(e){if(e){const{name:t,...i}=e;this.config.generatedIdentity={type:"byDefault",sequenceName:t,sequenceOptions:i}}else this.config.generatedIdentity={type:"byDefault"};return this.config.hasDefault=!0,this.config.notNull=!0,this}}class Ne extends we{static[a]="PgBigInt53Builder";constructor(e){super(e,"number","PgBigInt53")}build(e){return new ke(e,this.config)}}class ke extends S{static[a]="PgBigInt53";getSQLType(){return"bigint"}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}}class Se extends we{static[a]="PgBigInt64Builder";constructor(e){super(e,"bigint","PgBigInt64")}build(e){return new xe(e,this.config)}}class xe extends S{static[a]="PgBigInt64";getSQLType(){return"bigint"}mapFromDriverValue(e){return BigInt(e)}}function Ce(e,t){const{name:i,config:n}=ve(e,t);return"number"===n.mode?new Ne(i):new Se(i)}class qe extends k{static[a]="PgBigSerial53Builder";constructor(e){super(e,"number","PgBigSerial53"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new Te(e,this.config)}}class Te extends S{static[a]="PgBigSerial53";getSQLType(){return"bigserial"}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}}class je extends k{static[a]="PgBigSerial64Builder";constructor(e){super(e,"bigint","PgBigSerial64"),this.config.hasDefault=!0}build(e){return new $e(e,this.config)}}class $e extends S{static[a]="PgBigSerial64";getSQLType(){return"bigserial"}mapFromDriverValue(e){return BigInt(e)}}function Ae(e,t){const{name:i,config:n}=ve(e,t);return"number"===n.mode?new qe(i):new je(i)}class Pe extends k{static[a]="PgBooleanBuilder";constructor(e){super(e,"boolean","PgBoolean")}build(e){return new Be(e,this.config)}}class Be extends S{static[a]="PgBoolean";getSQLType(){return"boolean"}}function ze(e){return new Pe(e??"")}class De extends k{static[a]="PgCharBuilder";constructor(e,t){super(e,"string","PgChar"),this.config.length=t.length,this.config.enumValues=t.enum}build(e){return new Oe(e,this.config)}}class Oe extends S{static[a]="PgChar";length=this.config.length;enumValues=this.config.enumValues;getSQLType(){return void 0===this.length?"char":`char(${this.length})`}}function Le(e,t={}){const{name:i,config:n}=ve(e,t);return new De(i,n)}class Ie extends k{static[a]="PgCidrBuilder";constructor(e){super(e,"string","PgCidr")}build(e){return new Fe(e,this.config)}}class Fe extends S{static[a]="PgCidr";getSQLType(){return"cidr"}}function Qe(e){return new Ie(e??"")}class Ve extends k{static[a]="PgCustomColumnBuilder";constructor(e,t,i){super(e,"custom","PgCustomColumn"),this.config.fieldConfig=t,this.config.customTypeParams=i}build(e){return new Ee(e,this.config)}}class Ee extends S{static[a]="PgCustomColumn";sqlName;mapTo;mapFrom;constructor(e,t){super(e,t),this.sqlName=t.customTypeParams.dataType(t.fieldConfig),this.mapTo=t.customTypeParams.toDriver,this.mapFrom=t.customTypeParams.fromDriver}getSQLType(){return this.sqlName}mapFromDriverValue(e){return"function"==typeof this.mapFrom?this.mapFrom(e):e}mapToDriverValue(e){return"function"==typeof this.mapTo?this.mapTo(e):e}}function Ke(e){return(t,i)=>{const{name:n,config:s}=ve(t,i);return new Ve(n,s,e)}}class Ue extends k{static[a]="PgDateColumnBaseBuilder";defaultNow(){return this.default(ie`now()`)}}class Je extends Ue{static[a]="PgDateBuilder";constructor(e){super(e,"date","PgDate")}build(e){return new Re(e,this.config)}}class Re extends S{static[a]="PgDate";getSQLType(){return"date"}mapFromDriverValue(e){return"string"==typeof e?new Date(e):e}mapToDriverValue(e){return e.toISOString()}}class Me extends Ue{static[a]="PgDateStringBuilder";constructor(e){super(e,"string","PgDateString")}build(e){return new We(e,this.config)}}class We extends S{static[a]="PgDateString";getSQLType(){return"date"}mapFromDriverValue(e){return"string"==typeof e?e:e.toISOString().slice(0,-14)}}function He(e,t){const{name:i,config:n}=ve(e,t);return"date"===n?.mode?new Je(i):new Me(i)}class Ge extends k{static[a]="PgDoublePrecisionBuilder";constructor(e){super(e,"number","PgDoublePrecision")}build(e){return new Ye(e,this.config)}}class Ye extends S{static[a]="PgDoublePrecision";getSQLType(){return"double precision"}mapFromDriverValue(e){return"string"==typeof e?Number.parseFloat(e):e}}function Ze(e){return new Ge(e??"")}class Xe extends k{static[a]="PgInetBuilder";constructor(e){super(e,"string","PgInet")}build(e){return new et(e,this.config)}}class et extends S{static[a]="PgInet";getSQLType(){return"inet"}}function tt(e){return new Xe(e??"")}class it extends we{static[a]="PgIntegerBuilder";constructor(e){super(e,"number","PgInteger")}build(e){return new nt(e,this.config)}}class nt extends S{static[a]="PgInteger";getSQLType(){return"integer"}mapFromDriverValue(e){return"string"==typeof e?Number.parseInt(e):e}}function st(e){return new it(e??"")}class ot extends k{static[a]="PgIntervalBuilder";constructor(e,t){super(e,"string","PgInterval"),this.config.intervalConfig=t}build(e){return new at(e,this.config)}}class at extends S{static[a]="PgInterval";fields=this.config.intervalConfig.fields;precision=this.config.intervalConfig.precision;getSQLType(){return`interval${this.fields?` ${this.fields}`:""}${this.precision?`(${this.precision})`:""}`}}function rt(e,t={}){const{name:i,config:n}=ve(e,t);return new ot(i,n)}class _t extends k{static[a]="PgJsonBuilder";constructor(e){super(e,"json","PgJson")}build(e){return new lt(e,this.config)}}class lt extends S{static[a]="PgJson";constructor(e,t){super(e,t)}getSQLType(){return"json"}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if("string"==typeof e)try{return JSON.parse(e)}catch{return e}return e}}function ut(e){return new _t(e??"")}class dt extends k{static[a]="PgJsonbBuilder";constructor(e){super(e,"json","PgJsonb")}build(e){return new ct(e,this.config)}}class ct extends S{static[a]="PgJsonb";constructor(e,t){super(e,t)}getSQLType(){return"jsonb"}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if("string"==typeof e)try{return JSON.parse(e)}catch{return e}return e}}function mt(e){return new dt(e??"")}class pt extends k{static[a]="PgLineBuilder";constructor(e){super(e,"array","PgLine")}build(e){return new gt(e,this.config)}}class gt extends S{static[a]="PgLine";getSQLType(){return"line"}mapFromDriverValue(e){const[t,i,n]=e.slice(1,-1).split(",");return[Number.parseFloat(t),Number.parseFloat(i),Number.parseFloat(n)]}mapToDriverValue(e){return`{${e[0]},${e[1]},${e[2]}}`}}class ht extends k{static[a]="PgLineABCBuilder";constructor(e){super(e,"json","PgLineABC")}build(e){return new ft(e,this.config)}}class ft extends S{static[a]="PgLineABC";getSQLType(){return"line"}mapFromDriverValue(e){const[t,i,n]=e.slice(1,-1).split(",");return{a:Number.parseFloat(t),b:Number.parseFloat(i),c:Number.parseFloat(n)}}mapToDriverValue(e){return`{${e.a},${e.b},${e.c}}`}}function yt(e,t){const{name:i,config:n}=ve(e,t);return n?.mode&&"tuple"!==n.mode?new ht(i):new pt(i)}class bt extends k{static[a]="PgMacaddrBuilder";constructor(e){super(e,"string","PgMacaddr")}build(e){return new vt(e,this.config)}}class vt extends S{static[a]="PgMacaddr";getSQLType(){return"macaddr"}}function wt(e){return new bt(e??"")}class Nt extends k{static[a]="PgMacaddr8Builder";constructor(e){super(e,"string","PgMacaddr8")}build(e){return new kt(e,this.config)}}class kt extends S{static[a]="PgMacaddr8";getSQLType(){return"macaddr8"}}function St(e){return new Nt(e??"")}class xt extends k{static[a]="PgNumericBuilder";constructor(e,t,i){super(e,"string","PgNumeric"),this.config.precision=t,this.config.scale=i}build(e){return new Ct(e,this.config)}}class Ct extends S{static[a]="PgNumeric";precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return"string"==typeof e?e:String(e)}getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}class qt extends k{static[a]="PgNumericNumberBuilder";constructor(e,t,i){super(e,"number","PgNumericNumber"),this.config.precision=t,this.config.scale=i}build(e){return new Tt(e,this.config)}}class Tt extends S{static[a]="PgNumericNumber";precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}mapToDriverValue=String;getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}class jt extends k{static[a]="PgNumericBigIntBuilder";constructor(e,t,i){super(e,"bigint","PgNumericBigInt"),this.config.precision=t,this.config.scale=i}build(e){return new $t(e,this.config)}}class $t extends S{static[a]="PgNumericBigInt";precision;scale;constructor(e,t){super(e,t),this.precision=t.precision,this.scale=t.scale}mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}function At(e,t){const{name:i,config:n}=ve(e,t),s=n?.mode;return"number"===s?new qt(i,n?.precision,n?.scale):"bigint"===s?new jt(i,n?.precision,n?.scale):new xt(i,n?.precision,n?.scale)}class Pt extends k{static[a]="PgPointTupleBuilder";constructor(e){super(e,"array","PgPointTuple")}build(e){return new Bt(e,this.config)}}class Bt extends S{static[a]="PgPointTuple";getSQLType(){return"point"}mapFromDriverValue(e){if("string"==typeof e){const[t,i]=e.slice(1,-1).split(",");return[Number.parseFloat(t),Number.parseFloat(i)]}return[e.x,e.y]}mapToDriverValue(e){return`(${e[0]},${e[1]})`}}class zt extends k{static[a]="PgPointObjectBuilder";constructor(e){super(e,"json","PgPointObject")}build(e){return new Dt(e,this.config)}}class Dt extends S{static[a]="PgPointObject";getSQLType(){return"point"}mapFromDriverValue(e){if("string"==typeof e){const[t,i]=e.slice(1,-1).split(",");return{x:Number.parseFloat(t),y:Number.parseFloat(i)}}return e}mapToDriverValue(e){return`(${e.x},${e.y})`}}function Ot(e,t){const{name:i,config:n}=ve(e,t);return n?.mode&&"tuple"!==n.mode?new zt(i):new Pt(i)}function Lt(e,t){const i=new ArrayBuffer(8),n=new DataView(i);for(let i=0;i<8;i++)n.setUint8(i,e[t+i]);return n.getFloat64(0,!0)}function It(e){const t=function(e){const t=[];for(let i=0;i<e.length;i+=2)t.push(Number.parseInt(e.slice(i,i+2),16));return new Uint8Array(t)}(e);let i=0;const n=t[i];i+=1;const s=new DataView(t.buffer),o=s.getUint32(i,1===n);if(i+=4,536870912&o&&(s.getUint32(i,1===n),i+=4),1==(65535&o)){const e=Lt(t,i);i+=8;const n=Lt(t,i);return i+=8,[e,n]}throw new Error("Unsupported geometry type")}class Ft extends k{static[a]="PgGeometryBuilder";constructor(e){super(e,"array","PgGeometry")}build(e){return new Qt(e,this.config)}}class Qt extends S{static[a]="PgGeometry";getSQLType(){return"geometry(point)"}mapFromDriverValue(e){return It(e)}mapToDriverValue(e){return`point(${e[0]} ${e[1]})`}}class Vt extends k{static[a]="PgGeometryObjectBuilder";constructor(e){super(e,"json","PgGeometryObject")}build(e){return new Et(e,this.config)}}class Et extends S{static[a]="PgGeometryObject";getSQLType(){return"geometry(point)"}mapFromDriverValue(e){const t=It(e);return{x:t[0],y:t[1]}}mapToDriverValue(e){return`point(${e.x} ${e.y})`}}function Kt(e,t){const{name:i,config:n}=ve(e,t);return n?.mode&&"tuple"!==n.mode?new Vt(i):new Ft(i)}class Ut extends k{static[a]="PgRealBuilder";constructor(e,t){super(e,"number","PgReal"),this.config.length=t}build(e){return new Jt(e,this.config)}}class Jt extends S{static[a]="PgReal";constructor(e,t){super(e,t)}getSQLType(){return"real"}mapFromDriverValue=e=>"string"==typeof e?Number.parseFloat(e):e}function Rt(e){return new Ut(e??"")}class Mt extends k{static[a]="PgSerialBuilder";constructor(e){super(e,"number","PgSerial"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new Wt(e,this.config)}}class Wt extends S{static[a]="PgSerial";getSQLType(){return"serial"}}function Ht(e){return new Mt(e??"")}class Gt extends we{static[a]="PgSmallIntBuilder";constructor(e){super(e,"number","PgSmallInt")}build(e){return new Yt(e,this.config)}}class Yt extends S{static[a]="PgSmallInt";getSQLType(){return"smallint"}mapFromDriverValue=e=>"string"==typeof e?Number(e):e}function Zt(e){return new Gt(e??"")}class Xt extends k{static[a]="PgSmallSerialBuilder";constructor(e){super(e,"number","PgSmallSerial"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new ei(e,this.config)}}class ei extends S{static[a]="PgSmallSerial";getSQLType(){return"smallserial"}}function ti(e){return new Xt(e??"")}class ii extends k{static[a]="PgTextBuilder";constructor(e,t){super(e,"string","PgText"),this.config.enumValues=t.enum}build(e){return new ni(e,this.config)}}class ni extends S{static[a]="PgText";enumValues=this.config.enumValues;getSQLType(){return"text"}}function si(e,t={}){const{name:i,config:n}=ve(e,t);return new ii(i,n)}class oi extends Ue{constructor(e,t,i){super(e,"string","PgTime"),this.withTimezone=t,this.precision=i,this.config.withTimezone=t,this.config.precision=i}static[a]="PgTimeBuilder";build(e){return new ai(e,this.config)}}class ai extends S{static[a]="PgTime";withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`time${void 0===this.precision?"":`(${this.precision})`}${this.withTimezone?" with time zone":""}`}}function ri(e,t={}){const{name:i,config:n}=ve(e,t);return new oi(i,n.withTimezone??!1,n.precision)}class _i extends Ue{static[a]="PgTimestampBuilder";constructor(e,t,i){super(e,"date","PgTimestamp"),this.config.withTimezone=t,this.config.precision=i}build(e){return new li(e,this.config)}}class li extends S{static[a]="PgTimestamp";withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`timestamp${void 0===this.precision?"":` (${this.precision})`}${this.withTimezone?" with time zone":""}`}mapFromDriverValue(e){return"string"==typeof e?new Date(this.withTimezone?e:e+"+0000"):e}mapToDriverValue=e=>e.toISOString()}class ui extends Ue{static[a]="PgTimestampStringBuilder";constructor(e,t,i){super(e,"string","PgTimestampString"),this.config.withTimezone=t,this.config.precision=i}build(e){return new di(e,this.config)}}class di extends S{static[a]="PgTimestampString";withTimezone;precision;constructor(e,t){super(e,t),this.withTimezone=t.withTimezone,this.precision=t.precision}getSQLType(){return`timestamp${void 0===this.precision?"":`(${this.precision})`}${this.withTimezone?" with time zone":""}`}mapFromDriverValue(e){if("string"==typeof e)return e;const t=e.toISOString().slice(0,-1).replace("T"," ");if(this.withTimezone){const i=e.getTimezoneOffset();return`${t}${i<=0?"+":"-"}${Math.floor(Math.abs(i)/60).toString().padStart(2,"0")}`}return t}}function ci(e,t={}){const{name:i,config:n}=ve(e,t);return"string"===n?.mode?new ui(i,n.withTimezone??!1,n.precision):new _i(i,n?.withTimezone??!1,n?.precision)}class mi extends k{static[a]="PgUUIDBuilder";constructor(e){super(e,"string","PgUUID")}defaultRandom(){return this.default(ie`gen_random_uuid()`)}build(e){return new pi(e,this.config)}}class pi extends S{static[a]="PgUUID";getSQLType(){return"uuid"}}function gi(e){return new mi(e??"")}class hi extends k{static[a]="PgVarcharBuilder";constructor(e,t){super(e,"string","PgVarchar"),this.config.length=t.length,this.config.enumValues=t.enum}build(e){return new fi(e,this.config)}}class fi extends S{static[a]="PgVarchar";length=this.config.length;enumValues=this.config.enumValues;getSQLType(){return void 0===this.length?"varchar":`varchar(${this.length})`}}function yi(e,t={}){const{name:i,config:n}=ve(e,t);return new hi(i,n)}class bi extends k{static[a]="PgBinaryVectorBuilder";constructor(e,t){super(e,"string","PgBinaryVector"),this.config.dimensions=t.dimensions}build(e){return new vi(e,this.config)}}class vi extends S{static[a]="PgBinaryVector";dimensions=this.config.dimensions;getSQLType(){return`bit(${this.dimensions})`}}function wi(e,t){const{name:i,config:n}=ve(e,t);return new bi(i,n)}class Ni extends k{static[a]="PgHalfVectorBuilder";constructor(e,t){super(e,"array","PgHalfVector"),this.config.dimensions=t.dimensions}build(e){return new ki(e,this.config)}}class ki extends S{static[a]="PgHalfVector";dimensions=this.config.dimensions;getSQLType(){return`halfvec(${this.dimensions})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(",").map(e=>Number.parseFloat(e))}}function Si(e,t){const{name:i,config:n}=ve(e,t);return new Ni(i,n)}class xi extends k{static[a]="PgSparseVectorBuilder";constructor(e,t){super(e,"string","PgSparseVector"),this.config.dimensions=t.dimensions}build(e){return new Ci(e,this.config)}}class Ci extends S{static[a]="PgSparseVector";dimensions=this.config.dimensions;getSQLType(){return`sparsevec(${this.dimensions})`}}function qi(e,t){const{name:i,config:n}=ve(e,t);return new xi(i,n)}class Ti extends k{static[a]="PgVectorBuilder";constructor(e,t){super(e,"array","PgVector"),this.config.dimensions=t.dimensions}build(e){return new ji(e,this.config)}}class ji extends S{static[a]="PgVector";dimensions=this.config.dimensions;getSQLType(){return`vector(${this.dimensions})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(",").map(e=>Number.parseFloat(e))}}function $i(e,t){const{name:i,config:n}=ve(e,t);return new Ti(i,n)}class Ai{static[a]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}}class Pi{static[a]="SelectionProxyHandler";config;constructor(e){this.config={...e}}get(e,t){if("_"===t)return{...e._,selectedFields:new Proxy(e._.selectedFields,this)};if(t===L)return{...e[L],selectedFields:new Proxy(e[L].selectedFields,this)};if("symbol"==typeof t)return e[t];const i=(r(e,z)?e._.selectedFields:r(e,ae)?e[L].selectedFields:e)[t];if(r(i,Y.Aliased)){if("sql"===this.config.sqlAliasedBehavior&&!i.isSelectionField)return i.sql;const e=i.clone();return e.isSelectionField=!0,e}if(r(i,Y)){if("sql"===this.config.sqlBehavior)return i;throw new Error(`You tried to reference "${t}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`)}return r(i,_)?this.config.alias?new Proxy(i,new re(new Proxy(i.table,new _e(this.config.alias,this.config.replaceOriginalName??!1)))):i:"object"!=typeof i||null===i?i:new Proxy(i,new Pi(this.config))}}const Bi=Symbol.for("drizzle:PgInlineForeignKeys"),zi=Symbol.for("drizzle:EnableRLS");class Di extends R{static[a]="PgTable";static Symbol=Object.assign({},R.Symbol,{InlineForeignKeys:Bi,EnableRLS:zi});[Bi]=[];[zi]=!1;[R.Symbol.ExtraConfigBuilder]=void 0;[R.Symbol.ExtraConfigColumns]={}}function Oi(e,t,i,n,s=e){const o=new Di(e,n,s),a="function"==typeof t?t({bigint:Ce,bigserial:Ae,boolean:ze,char:Le,cidr:Qe,customType:Ke,date:He,doublePrecision:Ze,inet:tt,integer:st,interval:rt,json:ut,jsonb:mt,line:yt,macaddr:wt,macaddr8:St,numeric:At,point:Ot,geometry:Kt,real:Rt,serial:Ht,smallint:Zt,smallserial:ti,text:si,time:ri,timestamp:ci,uuid:gi,varchar:yi,bit:wi,halfvec:Si,sparsevec:qi,vector:$i}):t,r=Object.fromEntries(Object.entries(a).map(([e,t])=>{const i=t;i.setName(e);const n=i.build(o);return o[Bi].push(...i.buildForeignKeys(n,o)),[e,n]})),_=Object.fromEntries(Object.entries(a).map(([e,t])=>{const i=t;i.setName(e);return[e,i.buildExtraConfigColumn(o)]})),l=Object.assign(o,r);return l[R.Symbol.Columns]=r,l[R.Symbol.ExtraConfigColumns]=_,i&&(l[Di.Symbol.ExtraConfigBuilder]=i),Object.assign(l,{enableRLS:()=>(l[Di.Symbol.EnableRLS]=!0,l)})}const Li=(e,t,i)=>Oi(e,t,i,void 0);class Ii{constructor(e,t){this.unique=e,this.name=t}static[a]="PgIndexBuilderOn";on(...e){return new Fi(e.map(e=>{if(r(e,Y))return e;const t=new C(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=JSON.parse(JSON.stringify(e.defaultConfig)),t}),this.unique,!1,this.name)}onOnly(...e){return new Fi(e.map(e=>{if(r(e,Y))return e;const t=new C(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=e.defaultConfig,t}),this.unique,!0,this.name)}using(e,...t){return new Fi(t.map(e=>{if(r(e,Y))return e;const t=new C(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=JSON.parse(JSON.stringify(e.defaultConfig)),t}),this.unique,!0,this.name,e)}}class Fi{static[a]="PgIndexBuilder";config;constructor(e,t,i,n,s="btree"){this.config={name:n,columns:e,unique:t,only:i,method:s}}concurrently(){return this.config.concurrently=!0,this}with(e){return this.config.with=e,this}where(e){return this.config.where=e,this}build(e){return new Qi(this.config,e)}}class Qi{static[a]="PgIndex";config;constructor(e,t){this.config={...e,table:t}}}function Vi(e){return new Ii(!1,e)}function Ei(e){return new Ii(!0,e)}function Ki(...e){return e[0].columns?new Ui(e[0].columns,e[0].name):new Ui(e)}class Ui{static[a]="PgPrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new Ji(e,this.columns,this.name)}}class Ji{constructor(e,t,i){this.table=e,this.columns=t,this.name=i}static[a]="PgPrimaryKey";columns;name;getName(){return this.name??`${this.table[Di.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}const Ri=Symbol.for("drizzle:PgViewConfig");function Mi(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join("_")}function Wi(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,t,i)=>e+(0===i?t.toLowerCase():`${t[0].toUpperCase()}${t.slice(1)}`),"")}function Hi(e){return e}class Gi{static[a]="CasingCache";cache={};cachedTables={};convert;constructor(e){this.convert="snake_case"===e?Mi:"camelCase"===e?Wi:Hi}getColumnCasing(e){if(!e.keyAsName)return e.name;const t=`${e.table[R.Symbol.Schema]??"public"}.${e.table[R.Symbol.OriginalName]}.${e.name}`;return this.cache[t]||this.cacheTable(e.table),this.cache[t]}cacheTable(e){const t=`${e[R.Symbol.Schema]??"public"}.${e[R.Symbol.OriginalName]}`;if(!this.cachedTables[t]){for(const i of Object.values(e[R.Symbol.Columns])){const e=`${t}.${i.name}`;this.cache[e]=this.convert(i.name)}this.cachedTables[t]=!0}}clearCache(){this.cache={},this.cachedTables={}}}class Yi extends Error{static[a]="DrizzleError";constructor({message:e,cause:t}){super(e),this.name="DrizzleError",this.cause=t}}function Zi(e,t){return!function(e){return"object"==typeof e&&null!==e&&"mapToDriverValue"in e&&"function"==typeof e.mapToDriverValue}(t)||H(e)||r(e,te)||r(e,se)||r(e,_)||r(e,R)||r(e,ae)?e:new te(e,t)}const Xi=(e,t)=>ie`${e} = ${Zi(t,e)}`,en=(e,t)=>ie`${e} <> ${Zi(t,e)}`;function tn(...e){const t=e.filter(e=>void 0!==e);if(0!==t.length)return 1===t.length?new Y(t):new Y([new G("("),ie.join(t,new G(" and ")),new G(")")])}function nn(...e){const t=e.filter(e=>void 0!==e);if(0!==t.length)return 1===t.length?new Y(t):new Y([new G("("),ie.join(t,new G(" or ")),new G(")")])}function sn(e){return ie`not ${e}`}const on=(e,t)=>ie`${e} > ${Zi(t,e)}`,an=(e,t)=>ie`${e} >= ${Zi(t,e)}`,rn=(e,t)=>ie`${e} < ${Zi(t,e)}`,_n=(e,t)=>ie`${e} <= ${Zi(t,e)}`;function ln(e,t){return Array.isArray(t)?0===t.length?ie`false`:ie`${e} in ${t.map(t=>Zi(t,e))}`:ie`${e} in ${Zi(t,e)}`}function un(e,t){return Array.isArray(t)?0===t.length?ie`true`:ie`${e} not in ${t.map(t=>Zi(t,e))}`:ie`${e} not in ${Zi(t,e)}`}function dn(e){return ie`${e} is null`}function cn(e){return ie`${e} is not null`}function mn(e){return ie`exists ${e}`}function pn(e){return ie`not exists ${e}`}function gn(e,t,i){return ie`${e} between ${Zi(t,e)} and ${Zi(i,e)}`}function hn(e,t,i){return ie`${e} not between ${Zi(t,e)} and ${Zi(i,e)}`}function fn(e,t){return ie`${e} like ${t}`}function yn(e,t){return ie`${e} not like ${t}`}function bn(e,t){return ie`${e} ilike ${t}`}function vn(e,t){return ie`${e} not ilike ${t}`}function wn(e){return ie`${e} asc`}function Nn(e){return ie`${e} desc`}class kn{constructor(e,t,i){this.sourceTable=e,this.referencedTable=t,this.relationName=i,this.referencedTableName=t[R.Symbol.Name]}static[a]="Relation";referencedTableName;fieldName}class Sn extends kn{constructor(e,t,i,n){super(e,t,i?.relationName),this.config=i,this.isNullable=n}static[a]="One";withFieldName(e){const t=new Sn(this.sourceTable,this.referencedTable,this.config,this.isNullable);return t.fieldName=e,t}}class xn extends kn{constructor(e,t,i){super(e,t,i?.relationName),this.config=i}static[a]="Many";withFieldName(e){const t=new xn(this.sourceTable,this.referencedTable,this.config);return t.fieldName=e,t}}function Cn(e,t,i){if(r(i,Sn)&&i.config)return{fields:i.config.fields,references:i.config.references};const n=t[W(i.referencedTable)];if(!n)throw new Error(`Table "${i.referencedTable[R.Symbol.Name]}" not found in schema`);const s=e[n];if(!s)throw new Error(`Table "${n}" not found in schema`);const o=i.sourceTable,a=t[W(o)];if(!a)throw new Error(`Table "${o[R.Symbol.Name]}" not found in schema`);const _=[];for(const e of Object.values(s.relations))(i.relationName&&i!==e&&e.relationName===i.relationName||!i.relationName&&e.referencedTable===i.sourceTable)&&_.push(e);if(_.length>1)throw i.relationName?new Error(`There are multiple relations with name "${i.relationName}" in table "${n}"`):new Error(`There are multiple relations between "${n}" and "${i.sourceTable[R.Symbol.Name]}". Please specify relation name`);if(_[0]&&r(_[0],Sn)&&_[0].config)return{fields:_[0].config.references,references:_[0].config.fields};throw new Error(`There is not enough information to infer relation "${a}.${i.fieldName}"`)}class qn extends ae{static[a]="PgViewBase"}class Tn{static[a]="PgDialect";casing;constructor(e){this.casing=new Gi(e?.casing)}async migrate(e,t,i){const n="string"==typeof i?"__drizzle_migrations":i.migrationsTable??"__drizzle_migrations",s="string"==typeof i?"drizzle":i.migrationsSchema??"drizzle",o=ie`
|
|
2
|
-
CREATE TABLE IF NOT EXISTS ${
|
|
1
|
+
"use strict";var e=require("zod-to-camel-case"),i=require("drizzle-zod"),t=require("drizzle-orm"),s=require("zod");function n(e){return e&&e.__esModule?e:{default:e}}var _=n(e);const a=Symbol.for("drizzle:entityKind");function o(e,i){if(!e||"object"!=typeof e)return!1;if(e instanceof i)return!0;if(!Object.prototype.hasOwnProperty.call(i,a))throw new Error(`Class "${i.name??"<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let t=Object.getPrototypeOf(e).constructor;if(t)for(;t;){if(a in t&&t[a]===i[a])return!0;t=Object.getPrototypeOf(t)}return!1}class r{constructor(e,i){this.table=e,this.config=i,this.name=i.name,this.keyAsName=i.keyAsName,this.notNull=i.notNull,this.default=i.default,this.defaultFn=i.defaultFn,this.onUpdateFn=i.onUpdateFn,this.hasDefault=i.hasDefault,this.primary=i.primaryKey,this.isUnique=i.isUnique,this.uniqueName=i.uniqueName,this.uniqueType=i.uniqueType,this.dataType=i.dataType,this.columnType=i.columnType,this.generated=i.generated,this.generatedIdentity=i.generatedIdentity}static[a]="Column";name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;config;mapFromDriverValue(e){return e}mapToDriverValue(e){return e}shouldDisableInsert(){return void 0!==this.config.generated&&"byDefault"!==this.config.generated.type}}class l{static[a]="ColumnBuilder";config;constructor(e,i,t){this.config={name:e,keyAsName:""===e,notNull:!1,default:void 0,hasDefault:!1,primaryKey:!1,isUnique:!1,uniqueName:void 0,uniqueType:void 0,dataType:i,columnType:t,generated:void 0}}$type(){return this}notNull(){return this.config.notNull=!0,this}default(e){return this.config.default=e,this.config.hasDefault=!0,this}$defaultFn(e){return this.config.defaultFn=e,this.config.hasDefault=!0,this}$default=this.$defaultFn;$onUpdateFn(e){return this.config.onUpdateFn=e,this.config.hasDefault=!0,this}$onUpdate=this.$onUpdateFn;primaryKey(){return this.config.primaryKey=!0,this.config.notNull=!0,this}setName(e){""===this.config.name&&(this.config.name=e)}}const d=Symbol.for("drizzle:Name");class u{static[a]="PgForeignKeyBuilder";reference;_onUpdate="no action";_onDelete="no action";constructor(e,i){this.reference=()=>{const{name:i,columns:t,foreignColumns:s}=e();return{name:i,columns:t,foreignTable:s[0].table,foreignColumns:s}},i&&(this._onUpdate=i.onUpdate,this._onDelete=i.onDelete)}onUpdate(e){return this._onUpdate=void 0===e?"no action":e,this}onDelete(e){return this._onDelete=void 0===e?"no action":e,this}build(e){return new c(e,this)}}class c{constructor(e,i){this.table=e,this.reference=i.reference,this.onUpdate=i._onUpdate,this.onDelete=i._onDelete}static[a]="PgForeignKey";reference;onUpdate;onDelete;getName(){const{name:e,columns:i,foreignColumns:t}=this.reference(),s=i.map(e=>e.name),n=t.map(e=>e.name),_=[this.table[d],...s,t[0].table[d],...n];return e??`${_.join("_")}_fk`}}function m(e){return new u(function(){const{name:i,columns:t,foreignColumns:s}=e;return{name:i,columns:t,foreignColumns:s}})}function p(e){return new h(e)}function g(e,i){return`${e[d]}_${i.join("_")}_unique`}class f{constructor(e,i){this.name=i,this.columns=e}static[a]="PgUniqueConstraintBuilder";columns;nullsNotDistinctConfig=!1;nullsNotDistinct(){return this.nullsNotDistinctConfig=!0,this}build(e){return new v(e,this.columns,this.nullsNotDistinctConfig,this.name)}}class h{static[a]="PgUniqueOnConstraintBuilder";name;constructor(e){this.name=e}on(...e){return new f(e,this.name)}}class v{constructor(e,i,t,s){this.table=e,this.columns=i,this.name=s??g(this.table,this.columns.map(e=>e.name)),this.nullsNotDistinct=t}static[a]="PgUniqueConstraint";columns;name;nullsNotDistinct=!1;getName(){return this.name}}function y(e,i,t){for(let s=i;s<e.length;s++){const n=e[s];if("\\"!==n){if('"'===n)return[e.slice(i,s).replace(/\\/g,""),s+1];if(!t&&(","===n||"}"===n))return[e.slice(i,s).replace(/\\/g,""),s]}else s++}return[e.slice(i).replace(/\\/g,""),e.length]}function b(e,i=0){const t=[];let s=i,n=!1;for(;s<e.length;){const _=e[s];if(","===_){(n||s===i)&&t.push(""),n=!0,s++;continue}if(n=!1,"\\"===_){s+=2;continue}if('"'===_){const[i,n]=y(e,s+1,!0);t.push(i),s=n;continue}if("}"===_)return[t,s+1];if("{"===_){const[i,n]=b(e,s+1);t.push(i),s=n;continue}const[a,o]=y(e,s,!1);t.push(a),s=o}return[t,s]}function w(e){const[i]=b(e,1);return i}function N(e){return`{${e.map(e=>Array.isArray(e)?N(e):"string"==typeof e?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:`${e}`).join(",")}}`}class k extends l{foreignKeyConfigs=[];static[a]="PgColumnBuilder";array(e){return new C(this.config.name,this,e)}references(e,i={}){return this.foreignKeyConfigs.push({ref:e,actions:i}),this}unique(e,i){return this.config.isUnique=!0,this.config.uniqueName=e,this.config.uniqueType=i?.nulls,this}generatedAlwaysAs(e){return this.config.generated={as:e,type:"always",mode:"stored"},this}buildForeignKeys(e,i){return this.foreignKeyConfigs.map(({ref:t,actions:s})=>function(e,...i){return e(...i)}((t,s)=>{const n=new u(()=>{const i=t();return{columns:[e],foreignColumns:[i]}});return s.onUpdate&&n.onUpdate(s.onUpdate),s.onDelete&&n.onDelete(s.onDelete),n.build(i)},t,s))}buildExtraConfigColumn(e){return new x(e,this.config)}}class S extends r{constructor(e,i){i.uniqueName||(i.uniqueName=g(e,[i.name])),super(e,i),this.table=e}static[a]="PgColumn"}class x extends S{static[a]="ExtraConfigColumn";getSQLType(){return this.getSQLType()}indexConfig={order:this.config.order??"asc",nulls:this.config.nulls??"last",opClass:this.config.opClass};defaultConfig={order:"asc",nulls:"last",opClass:void 0};asc(){return this.indexConfig.order="asc",this}desc(){return this.indexConfig.order="desc",this}nullsFirst(){return this.indexConfig.nulls="first",this}nullsLast(){return this.indexConfig.nulls="last",this}op(e){return this.indexConfig.opClass=e,this}}class A{static[a]="IndexedColumn";constructor(e,i,t,s){this.name=e,this.keyAsName=i,this.type=t,this.indexConfig=s}name;keyAsName;type;indexConfig}class C extends k{static[a]="PgArrayBuilder";constructor(e,i,t){super(e,"array","PgArray"),this.config.baseBuilder=i,this.config.size=t}build(e){const i=this.config.baseBuilder.build(e);return new q(e,this.config,i)}}class q extends S{constructor(e,i,t,s){super(e,i),this.baseColumn=t,this.range=s,this.size=i.size}size;static[a]="PgArray";getSQLType(){return`${this.baseColumn.getSQLType()}[${"number"==typeof this.size?this.size:""}]`}mapFromDriverValue(e){return"string"==typeof e&&(e=w(e)),e.map(e=>this.baseColumn.mapFromDriverValue(e))}mapToDriverValue(e,i=!1){const t=e.map(e=>null===e?null:o(this.baseColumn,q)?this.baseColumn.mapToDriverValue(e,!0):this.baseColumn.mapToDriverValue(e));return i?t:N(t)}}class T extends k{static[a]="PgEnumObjectColumnBuilder";constructor(e,i){super(e,"string","PgEnumObjectColumn"),this.config.enum=i}build(e){return new j(e,this.config)}}class j extends S{static[a]="PgEnumObjectColumn";enum;enumValues=this.config.enum.enumValues;constructor(e,i){super(e,i),this.enum=i.enum}getSQLType(){return this.enum.enumName}}const $=Symbol.for("drizzle:isPgEnum");class P extends k{static[a]="PgEnumColumnBuilder";constructor(e,i){super(e,"string","PgEnumColumn"),this.config.enum=i}build(e){return new z(e,this.config)}}class z extends S{static[a]="PgEnumColumn";enum=this.config.enum;enumValues=this.config.enum.enumValues;constructor(e,i){super(e,i),this.enum=i.enum}getSQLType(){return this.enum.enumName}}class B{static[a]="Subquery";constructor(e,i,t,s=!1,n=[]){this._={brand:"Subquery",sql:e,selectedFields:i,alias:t,isWith:s,usedTables:n}}}class D extends B{static[a]="WithSubquery"}const O={startActiveSpan:(e,i)=>i()},L=Symbol.for("drizzle:ViewBaseConfig"),I=Symbol.for("drizzle:Schema"),F=Symbol.for("drizzle:Columns"),Q=Symbol.for("drizzle:ExtraConfigColumns"),E=Symbol.for("drizzle:OriginalName"),V=Symbol.for("drizzle:BaseName"),K=Symbol.for("drizzle:IsAlias"),U=Symbol.for("drizzle:ExtraConfigBuilder"),J=Symbol.for("drizzle:IsDrizzleTable");class R{static[a]="Table";static Symbol={Name:d,Schema:I,OriginalName:E,Columns:F,ExtraConfigColumns:Q,BaseName:V,IsAlias:K,ExtraConfigBuilder:U};[d];[E];[I];[F];[Q];[V];[K]=!1;[J]=!0;[U]=void 0;constructor(e,i,t){this[d]=this[E]=e,this[I]=i,this[V]=t}}function M(e){return e[d]}function W(e){return`${e[I]??"public"}.${e[d]}`}function H(e){return null!=e&&"function"==typeof e.getSQL}class G{static[a]="StringChunk";value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new Y([this])}}class Y{constructor(e){this.queryChunks=e;for(const i of e)if(o(i,R)){const e=i[R.Symbol.Schema];this.usedTables.push(void 0===e?i[R.Symbol.Name]:e+"."+i[R.Symbol.Name])}}static[a]="SQL";decoder=X;shouldInlineParams=!1;usedTables=[];append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return O.startActiveSpan("drizzle.buildSQL",i=>{const t=this.buildQueryFromSourceParams(this.queryChunks,e);return i?.setAttributes({"drizzle.query.text":t.sql,"drizzle.query.params":JSON.stringify(t.params)}),t})}buildQueryFromSourceParams(e,i){const t=Object.assign({},i,{inlineParams:i.inlineParams||this.shouldInlineParams,paramStartIndex:i.paramStartIndex||{value:0}}),{casing:s,escapeName:n,escapeParam:_,prepareTyping:a,inlineParams:l,paramStartIndex:d}=t;return function(e){const i={sql:"",params:[]};for(const t of e)i.sql+=t.sql,i.params.push(...t.params),t.typings?.length&&(i.typings||(i.typings=[]),i.typings.push(...t.typings));return i}(e.map(e=>{if(o(e,G))return{sql:e.value.join(""),params:[]};if(o(e,Z))return{sql:n(e.value),params:[]};if(void 0===e)return{sql:"",params:[]};if(Array.isArray(e)){const i=[new G("(")];for(const[t,s]of e.entries())i.push(s),t<e.length-1&&i.push(new G(", "));return i.push(new G(")")),this.buildQueryFromSourceParams(i,t)}if(o(e,Y))return this.buildQueryFromSourceParams(e.queryChunks,{...t,inlineParams:l||e.shouldInlineParams});if(o(e,R)){const i=e[R.Symbol.Schema],t=e[R.Symbol.Name];return{sql:void 0===i||e[K]?n(t):n(i)+"."+n(t),params:[]}}if(o(e,r)){const t=s.getColumnCasing(e);if("indexes"===i.invokeSource)return{sql:n(t),params:[]};const _=e.table[R.Symbol.Schema];return{sql:e.table[K]||void 0===_?n(e.table[R.Symbol.Name])+"."+n(t):n(_)+"."+n(e.table[R.Symbol.Name])+"."+n(t),params:[]}}if(o(e,ae)){const i=e[L].schema,t=e[L].name;return{sql:void 0===i||e[L].isAlias?n(t):n(i)+"."+n(t),params:[]}}if(o(e,ie)){if(o(e.value,ne))return{sql:_(d.value++,e),params:[e],typings:["none"]};const i=null===e.value?null:e.encoder.mapToDriverValue(e.value);if(o(i,Y))return this.buildQueryFromSourceParams([i],t);if(l)return{sql:this.mapInlineParam(i,t),params:[]};let s=["none"];return a&&(s=[a(e.encoder)]),{sql:_(d.value++,i),params:[i],typings:s}}return o(e,ne)?{sql:_(d.value++,e),params:[e],typings:["none"]}:o(e,Y.Aliased)&&void 0!==e.fieldAlias?{sql:n(e.fieldAlias),params:[]}:o(e,B)?e._.isWith?{sql:n(e._.alias),params:[]}:this.buildQueryFromSourceParams([new G("("),e._.sql,new G(") "),new Z(e._.alias)],t):(u=e)&&"function"==typeof u&&$ in u&&!0===u[$]?e.schema?{sql:n(e.schema)+"."+n(e.enumName),params:[]}:{sql:n(e.enumName),params:[]}:H(e)?e.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([e.getSQL()],t):this.buildQueryFromSourceParams([new G("("),e.getSQL(),new G(")")],t):l?{sql:this.mapInlineParam(e,t),params:[]}:{sql:_(d.value++,e),params:[e],typings:["none"]};var u}))}mapInlineParam(e,{escapeString:i}){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e)return e.toString();if("string"==typeof e)return i(e);if("object"==typeof e){const t=e.toString();return i("[object Object]"===t?JSON.stringify(e):t)}throw new Error("Unexpected param value: "+e)}getSQL(){return this}as(e){return void 0===e?this:new Y.Aliased(this,e)}mapWith(e){return this.decoder="function"==typeof e?{mapFromDriverValue:e}:e,this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}}class Z{constructor(e){this.value=e}static[a]="Name";brand;getSQL(){return new Y([this])}}const X={mapFromDriverValue:e=>e},ee={mapToDriverValue:e=>e};class ie{constructor(e,i=ee){this.value=e,this.encoder=i}static[a]="Param";brand;getSQL(){return new Y([this])}}function te(e,...i){const t=[];(i.length>0||e.length>0&&""!==e[0])&&t.push(new G(e[0]));for(const[s,n]of i.entries())t.push(n,new G(e[s+1]));return new Y(t)}var se;(se=te||(te={})).empty=function(){return new Y([])},se.fromList=function(e){return new Y(e)},se.raw=function(e){return new Y([new G(e)])},se.join=function(e,i){const t=[];for(const[s,n]of e.entries())s>0&&void 0!==i&&t.push(i),t.push(n);return new Y(t)},se.identifier=function(e){return new Z(e)},se.placeholder=function(e){return new ne(e)},se.param=function(e,i){return new ie(e,i)},(e=>{class i{constructor(e,i){this.sql=e,this.fieldAlias=i}static[a]="SQL.Aliased";isSelectionField=!1;getSQL(){return this.sql}clone(){return new i(this.sql,this.fieldAlias)}}e.Aliased=i})(Y||(Y={}));class ne{constructor(e){this.name=e}static[a]="Placeholder";getSQL(){return new Y([this])}}const _e=Symbol.for("drizzle:IsDrizzleView");class ae{static[a]="View";[L];[_e]=!0;constructor({name:e,schema:i,selectedFields:t,query:s}){this[L]={name:e,originalName:e,schema:i,selectedFields:t,query:s,isExisting:!s,isAlias:!1}}getSQL(){return new Y([this])}}r.prototype.getSQL=function(){return new Y([this])},R.prototype.getSQL=function(){return new Y([this])},B.prototype.getSQL=function(){return new Y([this])};class oe{constructor(e){this.table=e}static[a]="ColumnAliasProxyHandler";get(e,i){return"table"===i?this.table:e[i]}}class re{constructor(e,i){this.alias=e,this.replaceOriginalName=i}static[a]="TableAliasProxyHandler";get(e,i){if(i===R.Symbol.IsAlias)return!0;if(i===R.Symbol.Name)return this.alias;if(this.replaceOriginalName&&i===R.Symbol.OriginalName)return this.alias;if(i===L)return{...e[L],name:this.alias,isAlias:!0};if(i===R.Symbol.Columns){const i=e[R.Symbol.Columns];if(!i)return i;const t={};return Object.keys(i).map(s=>{t[s]=new Proxy(i[s],new oe(new Proxy(e,this)))}),t}const t=e[i];return o(t,r)?new Proxy(t,new oe(new Proxy(e,this))):t}}function le(e,i){return new Proxy(e,new re(i,!1))}function de(e,i){return new Proxy(e,new oe(new Proxy(e.table,new re(i,!1))))}function ue(e,i){return new Y.Aliased(ce(e.sql,i),e.fieldAlias)}function ce(e,i){return te.join(e.queryChunks.map(e=>o(e,r)?de(e,i):o(e,Y)?ce(e,i):o(e,Y.Aliased)?ue(e,i):e))}class me{constructor(e,i){this.name=e,this.value=i}static[a]="PgCheckBuilder";brand;build(e){return new pe(e,this)}}class pe{constructor(e,i){this.table=e,this.name=i.name,this.value=i.value}static[a]="PgCheck";name;value}function ge(e,i){return new me(e,i)}function fe(e,i){return Object.entries(e).reduce((e,[t,s])=>{if("string"!=typeof t)return e;const n=i?[...i,t]:[t];return o(s,r)||o(s,Y)||o(s,Y.Aliased)||o(s,B)?e.push({path:n,field:s}):o(s,R)?e.push(...fe(s[R.Symbol.Columns],n)):e.push(...fe(s,n)),e},[])}function he(e,i){const t=Object.keys(e),s=Object.keys(i);if(t.length!==s.length)return!1;for(const[e,i]of t.entries())if(i!==s[e])return!1;return!0}function ve(e){return e[R.Symbol.Columns]}function ye(e){return o(e,B)?e._.alias:o(e,ae)?e[L].name:o(e,Y)?void 0:e[R.Symbol.IsAlias]?e[R.Symbol.Name]:e[R.Symbol.BaseName]}function be(e,i){return{name:"string"==typeof e&&e.length>0?e:"",config:"object"==typeof e?e:i}}"undefined"!=typeof TextDecoder&&new TextDecoder;class we extends k{static[a]="PgIntColumnBaseBuilder";generatedAlwaysAsIdentity(e){if(e){const{name:i,...t}=e;this.config.generatedIdentity={type:"always",sequenceName:i,sequenceOptions:t}}else this.config.generatedIdentity={type:"always"};return this.config.hasDefault=!0,this.config.notNull=!0,this}generatedByDefaultAsIdentity(e){if(e){const{name:i,...t}=e;this.config.generatedIdentity={type:"byDefault",sequenceName:i,sequenceOptions:t}}else this.config.generatedIdentity={type:"byDefault"};return this.config.hasDefault=!0,this.config.notNull=!0,this}}class Ne extends we{static[a]="PgBigInt53Builder";constructor(e){super(e,"number","PgBigInt53")}build(e){return new ke(e,this.config)}}class ke extends S{static[a]="PgBigInt53";getSQLType(){return"bigint"}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}}class Se extends we{static[a]="PgBigInt64Builder";constructor(e){super(e,"bigint","PgBigInt64")}build(e){return new xe(e,this.config)}}class xe extends S{static[a]="PgBigInt64";getSQLType(){return"bigint"}mapFromDriverValue(e){return BigInt(e)}}function Ae(e,i){const{name:t,config:s}=be(e,i);return"number"===s.mode?new Ne(t):new Se(t)}class Ce extends k{static[a]="PgBigSerial53Builder";constructor(e){super(e,"number","PgBigSerial53"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new qe(e,this.config)}}class qe extends S{static[a]="PgBigSerial53";getSQLType(){return"bigserial"}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}}class Te extends k{static[a]="PgBigSerial64Builder";constructor(e){super(e,"bigint","PgBigSerial64"),this.config.hasDefault=!0}build(e){return new je(e,this.config)}}class je extends S{static[a]="PgBigSerial64";getSQLType(){return"bigserial"}mapFromDriverValue(e){return BigInt(e)}}function $e(e,i){const{name:t,config:s}=be(e,i);return"number"===s.mode?new Ce(t):new Te(t)}class Pe extends k{static[a]="PgBooleanBuilder";constructor(e){super(e,"boolean","PgBoolean")}build(e){return new ze(e,this.config)}}class ze extends S{static[a]="PgBoolean";getSQLType(){return"boolean"}}function Be(e){return new Pe(e??"")}class De extends k{static[a]="PgCharBuilder";constructor(e,i){super(e,"string","PgChar"),this.config.length=i.length,this.config.enumValues=i.enum}build(e){return new Oe(e,this.config)}}class Oe extends S{static[a]="PgChar";length=this.config.length;enumValues=this.config.enumValues;getSQLType(){return void 0===this.length?"char":`char(${this.length})`}}function Le(e,i={}){const{name:t,config:s}=be(e,i);return new De(t,s)}class Ie extends k{static[a]="PgCidrBuilder";constructor(e){super(e,"string","PgCidr")}build(e){return new Fe(e,this.config)}}class Fe extends S{static[a]="PgCidr";getSQLType(){return"cidr"}}function Qe(e){return new Ie(e??"")}class Ee extends k{static[a]="PgCustomColumnBuilder";constructor(e,i,t){super(e,"custom","PgCustomColumn"),this.config.fieldConfig=i,this.config.customTypeParams=t}build(e){return new Ve(e,this.config)}}class Ve extends S{static[a]="PgCustomColumn";sqlName;mapTo;mapFrom;constructor(e,i){super(e,i),this.sqlName=i.customTypeParams.dataType(i.fieldConfig),this.mapTo=i.customTypeParams.toDriver,this.mapFrom=i.customTypeParams.fromDriver}getSQLType(){return this.sqlName}mapFromDriverValue(e){return"function"==typeof this.mapFrom?this.mapFrom(e):e}mapToDriverValue(e){return"function"==typeof this.mapTo?this.mapTo(e):e}}function Ke(e){return(i,t)=>{const{name:s,config:n}=be(i,t);return new Ee(s,n,e)}}class Ue extends k{static[a]="PgDateColumnBaseBuilder";defaultNow(){return this.default(te`now()`)}}class Je extends Ue{static[a]="PgDateBuilder";constructor(e){super(e,"date","PgDate")}build(e){return new Re(e,this.config)}}class Re extends S{static[a]="PgDate";getSQLType(){return"date"}mapFromDriverValue(e){return"string"==typeof e?new Date(e):e}mapToDriverValue(e){return e.toISOString()}}class Me extends Ue{static[a]="PgDateStringBuilder";constructor(e){super(e,"string","PgDateString")}build(e){return new We(e,this.config)}}class We extends S{static[a]="PgDateString";getSQLType(){return"date"}mapFromDriverValue(e){return"string"==typeof e?e:e.toISOString().slice(0,-14)}}function He(e,i){const{name:t,config:s}=be(e,i);return"date"===s?.mode?new Je(t):new Me(t)}class Ge extends k{static[a]="PgDoublePrecisionBuilder";constructor(e){super(e,"number","PgDoublePrecision")}build(e){return new Ye(e,this.config)}}class Ye extends S{static[a]="PgDoublePrecision";getSQLType(){return"double precision"}mapFromDriverValue(e){return"string"==typeof e?Number.parseFloat(e):e}}function Ze(e){return new Ge(e??"")}class Xe extends k{static[a]="PgInetBuilder";constructor(e){super(e,"string","PgInet")}build(e){return new ei(e,this.config)}}class ei extends S{static[a]="PgInet";getSQLType(){return"inet"}}function ii(e){return new Xe(e??"")}class ti extends we{static[a]="PgIntegerBuilder";constructor(e){super(e,"number","PgInteger")}build(e){return new si(e,this.config)}}class si extends S{static[a]="PgInteger";getSQLType(){return"integer"}mapFromDriverValue(e){return"string"==typeof e?Number.parseInt(e):e}}function ni(e){return new ti(e??"")}class _i extends k{static[a]="PgIntervalBuilder";constructor(e,i){super(e,"string","PgInterval"),this.config.intervalConfig=i}build(e){return new ai(e,this.config)}}class ai extends S{static[a]="PgInterval";fields=this.config.intervalConfig.fields;precision=this.config.intervalConfig.precision;getSQLType(){return`interval${this.fields?` ${this.fields}`:""}${this.precision?`(${this.precision})`:""}`}}function oi(e,i={}){const{name:t,config:s}=be(e,i);return new _i(t,s)}class ri extends k{static[a]="PgJsonBuilder";constructor(e){super(e,"json","PgJson")}build(e){return new li(e,this.config)}}class li extends S{static[a]="PgJson";constructor(e,i){super(e,i)}getSQLType(){return"json"}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if("string"==typeof e)try{return JSON.parse(e)}catch{return e}return e}}function di(e){return new ri(e??"")}class ui extends k{static[a]="PgJsonbBuilder";constructor(e){super(e,"json","PgJsonb")}build(e){return new ci(e,this.config)}}class ci extends S{static[a]="PgJsonb";constructor(e,i){super(e,i)}getSQLType(){return"jsonb"}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){if("string"==typeof e)try{return JSON.parse(e)}catch{return e}return e}}function mi(e){return new ui(e??"")}class pi extends k{static[a]="PgLineBuilder";constructor(e){super(e,"array","PgLine")}build(e){return new gi(e,this.config)}}class gi extends S{static[a]="PgLine";getSQLType(){return"line"}mapFromDriverValue(e){const[i,t,s]=e.slice(1,-1).split(",");return[Number.parseFloat(i),Number.parseFloat(t),Number.parseFloat(s)]}mapToDriverValue(e){return`{${e[0]},${e[1]},${e[2]}}`}}class fi extends k{static[a]="PgLineABCBuilder";constructor(e){super(e,"json","PgLineABC")}build(e){return new hi(e,this.config)}}class hi extends S{static[a]="PgLineABC";getSQLType(){return"line"}mapFromDriverValue(e){const[i,t,s]=e.slice(1,-1).split(",");return{a:Number.parseFloat(i),b:Number.parseFloat(t),c:Number.parseFloat(s)}}mapToDriverValue(e){return`{${e.a},${e.b},${e.c}}`}}function vi(e,i){const{name:t,config:s}=be(e,i);return s?.mode&&"tuple"!==s.mode?new fi(t):new pi(t)}class yi extends k{static[a]="PgMacaddrBuilder";constructor(e){super(e,"string","PgMacaddr")}build(e){return new bi(e,this.config)}}class bi extends S{static[a]="PgMacaddr";getSQLType(){return"macaddr"}}function wi(e){return new yi(e??"")}class Ni extends k{static[a]="PgMacaddr8Builder";constructor(e){super(e,"string","PgMacaddr8")}build(e){return new ki(e,this.config)}}class ki extends S{static[a]="PgMacaddr8";getSQLType(){return"macaddr8"}}function Si(e){return new Ni(e??"")}class xi extends k{static[a]="PgNumericBuilder";constructor(e,i,t){super(e,"string","PgNumeric"),this.config.precision=i,this.config.scale=t}build(e){return new Ai(e,this.config)}}class Ai extends S{static[a]="PgNumeric";precision;scale;constructor(e,i){super(e,i),this.precision=i.precision,this.scale=i.scale}mapFromDriverValue(e){return"string"==typeof e?e:String(e)}getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}class Ci extends k{static[a]="PgNumericNumberBuilder";constructor(e,i,t){super(e,"number","PgNumericNumber"),this.config.precision=i,this.config.scale=t}build(e){return new qi(e,this.config)}}class qi extends S{static[a]="PgNumericNumber";precision;scale;constructor(e,i){super(e,i),this.precision=i.precision,this.scale=i.scale}mapFromDriverValue(e){return"number"==typeof e?e:Number(e)}mapToDriverValue=String;getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}class Ti extends k{static[a]="PgNumericBigIntBuilder";constructor(e,i,t){super(e,"bigint","PgNumericBigInt"),this.config.precision=i,this.config.scale=t}build(e){return new ji(e,this.config)}}class ji extends S{static[a]="PgNumericBigInt";precision;scale;constructor(e,i){super(e,i),this.precision=i.precision,this.scale=i.scale}mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return void 0!==this.precision&&void 0!==this.scale?`numeric(${this.precision}, ${this.scale})`:void 0===this.precision?"numeric":`numeric(${this.precision})`}}function $i(e,i){const{name:t,config:s}=be(e,i),n=s?.mode;return"number"===n?new Ci(t,s?.precision,s?.scale):"bigint"===n?new Ti(t,s?.precision,s?.scale):new xi(t,s?.precision,s?.scale)}class Pi extends k{static[a]="PgPointTupleBuilder";constructor(e){super(e,"array","PgPointTuple")}build(e){return new zi(e,this.config)}}class zi extends S{static[a]="PgPointTuple";getSQLType(){return"point"}mapFromDriverValue(e){if("string"==typeof e){const[i,t]=e.slice(1,-1).split(",");return[Number.parseFloat(i),Number.parseFloat(t)]}return[e.x,e.y]}mapToDriverValue(e){return`(${e[0]},${e[1]})`}}class Bi extends k{static[a]="PgPointObjectBuilder";constructor(e){super(e,"json","PgPointObject")}build(e){return new Di(e,this.config)}}class Di extends S{static[a]="PgPointObject";getSQLType(){return"point"}mapFromDriverValue(e){if("string"==typeof e){const[i,t]=e.slice(1,-1).split(",");return{x:Number.parseFloat(i),y:Number.parseFloat(t)}}return e}mapToDriverValue(e){return`(${e.x},${e.y})`}}function Oi(e,i){const{name:t,config:s}=be(e,i);return s?.mode&&"tuple"!==s.mode?new Bi(t):new Pi(t)}function Li(e,i){const t=new ArrayBuffer(8),s=new DataView(t);for(let t=0;t<8;t++)s.setUint8(t,e[i+t]);return s.getFloat64(0,!0)}function Ii(e){const i=function(e){const i=[];for(let t=0;t<e.length;t+=2)i.push(Number.parseInt(e.slice(t,t+2),16));return new Uint8Array(i)}(e);let t=0;const s=i[t];t+=1;const n=new DataView(i.buffer),_=n.getUint32(t,1===s);if(t+=4,536870912&_&&(n.getUint32(t,1===s),t+=4),1==(65535&_)){const e=Li(i,t);t+=8;const s=Li(i,t);return t+=8,[e,s]}throw new Error("Unsupported geometry type")}class Fi extends k{static[a]="PgGeometryBuilder";constructor(e){super(e,"array","PgGeometry")}build(e){return new Qi(e,this.config)}}class Qi extends S{static[a]="PgGeometry";getSQLType(){return"geometry(point)"}mapFromDriverValue(e){return Ii(e)}mapToDriverValue(e){return`point(${e[0]} ${e[1]})`}}class Ei extends k{static[a]="PgGeometryObjectBuilder";constructor(e){super(e,"json","PgGeometryObject")}build(e){return new Vi(e,this.config)}}class Vi extends S{static[a]="PgGeometryObject";getSQLType(){return"geometry(point)"}mapFromDriverValue(e){const i=Ii(e);return{x:i[0],y:i[1]}}mapToDriverValue(e){return`point(${e.x} ${e.y})`}}function Ki(e,i){const{name:t,config:s}=be(e,i);return s?.mode&&"tuple"!==s.mode?new Ei(t):new Fi(t)}class Ui extends k{static[a]="PgRealBuilder";constructor(e,i){super(e,"number","PgReal"),this.config.length=i}build(e){return new Ji(e,this.config)}}class Ji extends S{static[a]="PgReal";constructor(e,i){super(e,i)}getSQLType(){return"real"}mapFromDriverValue=e=>"string"==typeof e?Number.parseFloat(e):e}function Ri(e){return new Ui(e??"")}class Mi extends k{static[a]="PgSerialBuilder";constructor(e){super(e,"number","PgSerial"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new Wi(e,this.config)}}class Wi extends S{static[a]="PgSerial";getSQLType(){return"serial"}}function Hi(e){return new Mi(e??"")}class Gi extends we{static[a]="PgSmallIntBuilder";constructor(e){super(e,"number","PgSmallInt")}build(e){return new Yi(e,this.config)}}class Yi extends S{static[a]="PgSmallInt";getSQLType(){return"smallint"}mapFromDriverValue=e=>"string"==typeof e?Number(e):e}function Zi(e){return new Gi(e??"")}class Xi extends k{static[a]="PgSmallSerialBuilder";constructor(e){super(e,"number","PgSmallSerial"),this.config.hasDefault=!0,this.config.notNull=!0}build(e){return new et(e,this.config)}}class et extends S{static[a]="PgSmallSerial";getSQLType(){return"smallserial"}}function it(e){return new Xi(e??"")}class tt extends k{static[a]="PgTextBuilder";constructor(e,i){super(e,"string","PgText"),this.config.enumValues=i.enum}build(e){return new st(e,this.config)}}class st extends S{static[a]="PgText";enumValues=this.config.enumValues;getSQLType(){return"text"}}function nt(e,i={}){const{name:t,config:s}=be(e,i);return new tt(t,s)}class _t extends Ue{constructor(e,i,t){super(e,"string","PgTime"),this.withTimezone=i,this.precision=t,this.config.withTimezone=i,this.config.precision=t}static[a]="PgTimeBuilder";build(e){return new at(e,this.config)}}class at extends S{static[a]="PgTime";withTimezone;precision;constructor(e,i){super(e,i),this.withTimezone=i.withTimezone,this.precision=i.precision}getSQLType(){return`time${void 0===this.precision?"":`(${this.precision})`}${this.withTimezone?" with time zone":""}`}}function ot(e,i={}){const{name:t,config:s}=be(e,i);return new _t(t,s.withTimezone??!1,s.precision)}class rt extends Ue{static[a]="PgTimestampBuilder";constructor(e,i,t){super(e,"date","PgTimestamp"),this.config.withTimezone=i,this.config.precision=t}build(e){return new lt(e,this.config)}}class lt extends S{static[a]="PgTimestamp";withTimezone;precision;constructor(e,i){super(e,i),this.withTimezone=i.withTimezone,this.precision=i.precision}getSQLType(){return`timestamp${void 0===this.precision?"":` (${this.precision})`}${this.withTimezone?" with time zone":""}`}mapFromDriverValue(e){return"string"==typeof e?new Date(this.withTimezone?e:e+"+0000"):e}mapToDriverValue=e=>e.toISOString()}class dt extends Ue{static[a]="PgTimestampStringBuilder";constructor(e,i,t){super(e,"string","PgTimestampString"),this.config.withTimezone=i,this.config.precision=t}build(e){return new ut(e,this.config)}}class ut extends S{static[a]="PgTimestampString";withTimezone;precision;constructor(e,i){super(e,i),this.withTimezone=i.withTimezone,this.precision=i.precision}getSQLType(){return`timestamp${void 0===this.precision?"":`(${this.precision})`}${this.withTimezone?" with time zone":""}`}mapFromDriverValue(e){if("string"==typeof e)return e;const i=e.toISOString().slice(0,-1).replace("T"," ");if(this.withTimezone){const t=e.getTimezoneOffset();return`${i}${t<=0?"+":"-"}${Math.floor(Math.abs(t)/60).toString().padStart(2,"0")}`}return i}}function ct(e,i={}){const{name:t,config:s}=be(e,i);return"string"===s?.mode?new dt(t,s.withTimezone??!1,s.precision):new rt(t,s?.withTimezone??!1,s?.precision)}class mt extends k{static[a]="PgUUIDBuilder";constructor(e){super(e,"string","PgUUID")}defaultRandom(){return this.default(te`gen_random_uuid()`)}build(e){return new pt(e,this.config)}}class pt extends S{static[a]="PgUUID";getSQLType(){return"uuid"}}function gt(e){return new mt(e??"")}class ft extends k{static[a]="PgVarcharBuilder";constructor(e,i){super(e,"string","PgVarchar"),this.config.length=i.length,this.config.enumValues=i.enum}build(e){return new ht(e,this.config)}}class ht extends S{static[a]="PgVarchar";length=this.config.length;enumValues=this.config.enumValues;getSQLType(){return void 0===this.length?"varchar":`varchar(${this.length})`}}function vt(e,i={}){const{name:t,config:s}=be(e,i);return new ft(t,s)}class yt extends k{static[a]="PgBinaryVectorBuilder";constructor(e,i){super(e,"string","PgBinaryVector"),this.config.dimensions=i.dimensions}build(e){return new bt(e,this.config)}}class bt extends S{static[a]="PgBinaryVector";dimensions=this.config.dimensions;getSQLType(){return`bit(${this.dimensions})`}}function wt(e,i){const{name:t,config:s}=be(e,i);return new yt(t,s)}class Nt extends k{static[a]="PgHalfVectorBuilder";constructor(e,i){super(e,"array","PgHalfVector"),this.config.dimensions=i.dimensions}build(e){return new kt(e,this.config)}}class kt extends S{static[a]="PgHalfVector";dimensions=this.config.dimensions;getSQLType(){return`halfvec(${this.dimensions})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(",").map(e=>Number.parseFloat(e))}}function St(e,i){const{name:t,config:s}=be(e,i);return new Nt(t,s)}class xt extends k{static[a]="PgSparseVectorBuilder";constructor(e,i){super(e,"string","PgSparseVector"),this.config.dimensions=i.dimensions}build(e){return new At(e,this.config)}}class At extends S{static[a]="PgSparseVector";dimensions=this.config.dimensions;getSQLType(){return`sparsevec(${this.dimensions})`}}function Ct(e,i){const{name:t,config:s}=be(e,i);return new xt(t,s)}class qt extends k{static[a]="PgVectorBuilder";constructor(e,i){super(e,"array","PgVector"),this.config.dimensions=i.dimensions}build(e){return new Tt(e,this.config)}}class Tt extends S{static[a]="PgVector";dimensions=this.config.dimensions;getSQLType(){return`vector(${this.dimensions})`}mapToDriverValue(e){return JSON.stringify(e)}mapFromDriverValue(e){return e.slice(1,-1).split(",").map(e=>Number.parseFloat(e))}}function jt(e,i){const{name:t,config:s}=be(e,i);return new qt(t,s)}class $t{static[a]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(i=>(e?.(),i),i=>{throw e?.(),i})}then(e,i){return this.execute().then(e,i)}}class Pt{static[a]="SelectionProxyHandler";config;constructor(e){this.config={...e}}get(e,i){if("_"===i)return{...e._,selectedFields:new Proxy(e._.selectedFields,this)};if(i===L)return{...e[L],selectedFields:new Proxy(e[L].selectedFields,this)};if("symbol"==typeof i)return e[i];const t=(o(e,B)?e._.selectedFields:o(e,ae)?e[L].selectedFields:e)[i];if(o(t,Y.Aliased)){if("sql"===this.config.sqlAliasedBehavior&&!t.isSelectionField)return t.sql;const e=t.clone();return e.isSelectionField=!0,e}if(o(t,Y)){if("sql"===this.config.sqlBehavior)return t;throw new Error(`You tried to reference "${i}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`)}return o(t,r)?this.config.alias?new Proxy(t,new oe(new Proxy(t.table,new re(this.config.alias,this.config.replaceOriginalName??!1)))):t:"object"!=typeof t||null===t?t:new Proxy(t,new Pt(this.config))}}const zt=Symbol.for("drizzle:PgInlineForeignKeys"),Bt=Symbol.for("drizzle:EnableRLS");class Dt extends R{static[a]="PgTable";static Symbol=Object.assign({},R.Symbol,{InlineForeignKeys:zt,EnableRLS:Bt});[zt]=[];[Bt]=!1;[R.Symbol.ExtraConfigBuilder]=void 0;[R.Symbol.ExtraConfigColumns]={}}function Ot(e,i,t,s,n=e){const _=new Dt(e,s,n),a="function"==typeof i?i({bigint:Ae,bigserial:$e,boolean:Be,char:Le,cidr:Qe,customType:Ke,date:He,doublePrecision:Ze,inet:ii,integer:ni,interval:oi,json:di,jsonb:mi,line:vi,macaddr:wi,macaddr8:Si,numeric:$i,point:Oi,geometry:Ki,real:Ri,serial:Hi,smallint:Zi,smallserial:it,text:nt,time:ot,timestamp:ct,uuid:gt,varchar:vt,bit:wt,halfvec:St,sparsevec:Ct,vector:jt}):i,o=Object.fromEntries(Object.entries(a).map(([e,i])=>{const t=i;t.setName(e);const s=t.build(_);return _[zt].push(...t.buildForeignKeys(s,_)),[e,s]})),r=Object.fromEntries(Object.entries(a).map(([e,i])=>{const t=i;t.setName(e);return[e,t.buildExtraConfigColumn(_)]})),l=Object.assign(_,o);return l[R.Symbol.Columns]=o,l[R.Symbol.ExtraConfigColumns]=r,t&&(l[Dt.Symbol.ExtraConfigBuilder]=t),Object.assign(l,{enableRLS:()=>(l[Dt.Symbol.EnableRLS]=!0,l)})}const Lt=(e,i,t)=>Ot(e,i,t,void 0);class It{constructor(e,i){this.unique=e,this.name=i}static[a]="PgIndexBuilderOn";on(...e){return new Ft(e.map(e=>{if(o(e,Y))return e;const i=new A(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=JSON.parse(JSON.stringify(e.defaultConfig)),i}),this.unique,!1,this.name)}onOnly(...e){return new Ft(e.map(e=>{if(o(e,Y))return e;const i=new A(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=e.defaultConfig,i}),this.unique,!0,this.name)}using(e,...i){return new Ft(i.map(e=>{if(o(e,Y))return e;const i=new A(e.name,!!e.keyAsName,e.columnType,e.indexConfig);return e.indexConfig=JSON.parse(JSON.stringify(e.defaultConfig)),i}),this.unique,!0,this.name,e)}}class Ft{static[a]="PgIndexBuilder";config;constructor(e,i,t,s,n="btree"){this.config={name:s,columns:e,unique:i,only:t,method:n}}concurrently(){return this.config.concurrently=!0,this}with(e){return this.config.with=e,this}where(e){return this.config.where=e,this}build(e){return new Qt(this.config,e)}}class Qt{static[a]="PgIndex";config;constructor(e,i){this.config={...e,table:i}}}function Et(e){return new It(!1,e)}function Vt(e){return new It(!0,e)}function Kt(...e){return e[0].columns?new Ut(e[0].columns,e[0].name):new Ut(e)}class Ut{static[a]="PgPrimaryKeyBuilder";columns;name;constructor(e,i){this.columns=e,this.name=i}build(e){return new Jt(e,this.columns,this.name)}}class Jt{constructor(e,i,t){this.table=e,this.columns=i,this.name=t}static[a]="PgPrimaryKey";columns;name;getName(){return this.name??`${this.table[Dt.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}const Rt=Symbol.for("drizzle:PgViewConfig");function Mt(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join("_")}function Wt(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,i,t)=>e+(0===t?i.toLowerCase():`${i[0].toUpperCase()}${i.slice(1)}`),"")}function Ht(e){return e}class Gt{static[a]="CasingCache";cache={};cachedTables={};convert;constructor(e){this.convert="snake_case"===e?Mt:"camelCase"===e?Wt:Ht}getColumnCasing(e){if(!e.keyAsName)return e.name;const i=`${e.table[R.Symbol.Schema]??"public"}.${e.table[R.Symbol.OriginalName]}.${e.name}`;return this.cache[i]||this.cacheTable(e.table),this.cache[i]}cacheTable(e){const i=`${e[R.Symbol.Schema]??"public"}.${e[R.Symbol.OriginalName]}`;if(!this.cachedTables[i]){for(const t of Object.values(e[R.Symbol.Columns])){const e=`${i}.${t.name}`;this.cache[e]=this.convert(t.name)}this.cachedTables[i]=!0}}clearCache(){this.cache={},this.cachedTables={}}}class Yt extends Error{static[a]="DrizzleError";constructor({message:e,cause:i}){super(e),this.name="DrizzleError",this.cause=i}}function Zt(e,i){return!function(e){return"object"==typeof e&&null!==e&&"mapToDriverValue"in e&&"function"==typeof e.mapToDriverValue}(i)||H(e)||o(e,ie)||o(e,ne)||o(e,r)||o(e,R)||o(e,ae)?e:new ie(e,i)}const Xt=(e,i)=>te`${e} = ${Zt(i,e)}`,es=(e,i)=>te`${e} <> ${Zt(i,e)}`;function is(...e){const i=e.filter(e=>void 0!==e);if(0!==i.length)return 1===i.length?new Y(i):new Y([new G("("),te.join(i,new G(" and ")),new G(")")])}function ts(...e){const i=e.filter(e=>void 0!==e);if(0!==i.length)return 1===i.length?new Y(i):new Y([new G("("),te.join(i,new G(" or ")),new G(")")])}function ss(e){return te`not ${e}`}const ns=(e,i)=>te`${e} > ${Zt(i,e)}`,_s=(e,i)=>te`${e} >= ${Zt(i,e)}`,as=(e,i)=>te`${e} < ${Zt(i,e)}`,os=(e,i)=>te`${e} <= ${Zt(i,e)}`;function rs(e,i){return Array.isArray(i)?0===i.length?te`false`:te`${e} in ${i.map(i=>Zt(i,e))}`:te`${e} in ${Zt(i,e)}`}function ls(e,i){return Array.isArray(i)?0===i.length?te`true`:te`${e} not in ${i.map(i=>Zt(i,e))}`:te`${e} not in ${Zt(i,e)}`}function ds(e){return te`${e} is null`}function us(e){return te`${e} is not null`}function cs(e){return te`exists ${e}`}function ms(e){return te`not exists ${e}`}function ps(e,i,t){return te`${e} between ${Zt(i,e)} and ${Zt(t,e)}`}function gs(e,i,t){return te`${e} not between ${Zt(i,e)} and ${Zt(t,e)}`}function fs(e,i){return te`${e} like ${i}`}function hs(e,i){return te`${e} not like ${i}`}function vs(e,i){return te`${e} ilike ${i}`}function ys(e,i){return te`${e} not ilike ${i}`}function bs(e){return te`${e} asc`}function ws(e){return te`${e} desc`}class Ns{constructor(e,i,t){this.sourceTable=e,this.referencedTable=i,this.relationName=t,this.referencedTableName=i[R.Symbol.Name]}static[a]="Relation";referencedTableName;fieldName}class ks extends Ns{constructor(e,i,t,s){super(e,i,t?.relationName),this.config=t,this.isNullable=s}static[a]="One";withFieldName(e){const i=new ks(this.sourceTable,this.referencedTable,this.config,this.isNullable);return i.fieldName=e,i}}class Ss extends Ns{constructor(e,i,t){super(e,i,t?.relationName),this.config=t}static[a]="Many";withFieldName(e){const i=new Ss(this.sourceTable,this.referencedTable,this.config);return i.fieldName=e,i}}function xs(e,i,t){if(o(t,ks)&&t.config)return{fields:t.config.fields,references:t.config.references};const s=i[W(t.referencedTable)];if(!s)throw new Error(`Table "${t.referencedTable[R.Symbol.Name]}" not found in schema`);const n=e[s];if(!n)throw new Error(`Table "${s}" not found in schema`);const _=t.sourceTable,a=i[W(_)];if(!a)throw new Error(`Table "${_[R.Symbol.Name]}" not found in schema`);const r=[];for(const e of Object.values(n.relations))(t.relationName&&t!==e&&e.relationName===t.relationName||!t.relationName&&e.referencedTable===t.sourceTable)&&r.push(e);if(r.length>1)throw t.relationName?new Error(`There are multiple relations with name "${t.relationName}" in table "${s}"`):new Error(`There are multiple relations between "${s}" and "${t.sourceTable[R.Symbol.Name]}". Please specify relation name`);if(r[0]&&o(r[0],ks)&&r[0].config)return{fields:r[0].config.references,references:r[0].config.fields};throw new Error(`There is not enough information to infer relation "${a}.${t.fieldName}"`)}class As extends ae{static[a]="PgViewBase"}class Cs{static[a]="PgDialect";casing;constructor(e){this.casing=new Gt(e?.casing)}async migrate(e,i,t){const s="string"==typeof t?"__drizzle_migrations":t.migrationsTable??"__drizzle_migrations",n="string"==typeof t?"drizzle":t.migrationsSchema??"drizzle",_=te`
|
|
2
|
+
CREATE TABLE IF NOT EXISTS ${te.identifier(n)}.${te.identifier(s)} (
|
|
3
3
|
id SERIAL PRIMARY KEY,
|
|
4
4
|
hash text NOT NULL,
|
|
5
5
|
created_at bigint
|
|
6
6
|
)
|
|
7
|
-
`;await t.execute(ie`CREATE SCHEMA IF NOT EXISTS ${ie.identifier(s)}`),await t.execute(o);const a=(await t.all(ie`select id, hash, created_at from ${ie.identifier(s)}.${ie.identifier(n)} order by created_at desc limit 1`))[0];await t.transaction(async t=>{for await(const i of e)if(!a||Number(a.created_at)<i.folderMillis){for(const e of i.sql)await t.execute(ie.raw(e));await t.execute(ie`insert into ${ie.identifier(s)}.${ie.identifier(n)} ("hash", "created_at") values(${i.hash}, ${i.folderMillis})`)}})}escapeName(e){return`"${e.replace(/"/g,'""')}"`}escapeParam(e){return`$${e+1}`}escapeString(e){return`'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;const t=[ie`with `];for(const[i,n]of e.entries())t.push(ie`${ie.identifier(n._.alias)} as (${n._.sql})`),i<e.length-1&&t.push(ie`, `);return t.push(ie` `),ie.join(t)}buildDeleteQuery({table:e,where:t,returning:i,withList:n}){return ie`${this.buildWithCTE(n)}delete from ${e}${t?ie` where ${t}`:void 0}${i?ie` returning ${this.buildSelection(i,{isSingleTable:!0})}`:void 0}`}buildUpdateSet(e,t){const i=e[R.Symbol.Columns],n=Object.keys(i).filter(e=>void 0!==t[e]||void 0!==i[e]?.onUpdateFn),s=n.length;return ie.join(n.flatMap((e,n)=>{const o=i[e],a=o.onUpdateFn?.(),_=t[e]??(r(a,Y)?a:ie.param(a,o)),l=ie`${ie.identifier(this.casing.getColumnCasing(o))} = ${_}`;return n<s-1?[l,ie.raw(", ")]:[l]}))}buildUpdateQuery({table:e,set:t,where:i,returning:n,withList:s,from:o,joins:a}){const r=this.buildWithCTE(s),_=e[Di.Symbol.Name],l=e[Di.Symbol.Schema],u=e[Di.Symbol.OriginalName],d=_===u?void 0:_,c=ie`${l?ie`${ie.identifier(l)}.`:void 0}${ie.identifier(u)}${d&&ie` ${ie.identifier(d)}`}`,m=this.buildUpdateSet(e,t),p=o&&ie.join([ie.raw(" from "),this.buildFromTable(o)]);return ie`${r}update ${c} set ${m}${p}${this.buildJoins(a)}${i?ie` where ${i}`:void 0}${n?ie` returning ${this.buildSelection(n,{isSingleTable:!o})}`:void 0}`}buildSelection(e,{isSingleTable:t=!1}={}){const i=e.length,n=e.flatMap(({field:e},n)=>{const s=[];if(r(e,Y.Aliased)&&e.isSelectionField)s.push(ie.identifier(e.fieldAlias));else if(r(e,Y.Aliased)||r(e,Y)){const i=r(e,Y.Aliased)?e.sql:e;t?s.push(new Y(i.queryChunks.map(e=>r(e,S)?ie.identifier(this.casing.getColumnCasing(e)):e))):s.push(i),r(e,Y.Aliased)&&s.push(ie` as ${ie.identifier(e.fieldAlias)}`)}else if(r(e,_))t?s.push(ie.identifier(this.casing.getColumnCasing(e))):s.push(e);else if(r(e,z)){const t=Object.entries(e._.selectedFields);if(1===t.length){const i=t[0][1],n=r(i,Y)?i.decoder:r(i,_)?{mapFromDriverValue:e=>i.mapFromDriverValue(e)}:i.sql.decoder;n&&(e._.sql.decoder=n)}s.push(e)}return n<i-1&&s.push(ie`, `),s});return ie.join(n)}buildJoins(e){if(!e||0===e.length)return;const t=[];for(const[i,n]of e.entries()){0===i&&t.push(ie` `);const s=n.table,o=n.lateral?ie` lateral`:void 0,a=n.on?ie` on ${n.on}`:void 0;if(r(s,Di)){const e=s[Di.Symbol.Name],i=s[Di.Symbol.Schema],r=s[Di.Symbol.OriginalName],_=e===r?void 0:n.alias;t.push(ie`${ie.raw(n.joinType)} join${o} ${i?ie`${ie.identifier(i)}.`:void 0}${ie.identifier(r)}${_&&ie` ${ie.identifier(_)}`}${a}`)}else if(r(s,ae)){const e=s[L].name,i=s[L].schema,r=s[L].originalName,_=e===r?void 0:n.alias;t.push(ie`${ie.raw(n.joinType)} join${o} ${i?ie`${ie.identifier(i)}.`:void 0}${ie.identifier(r)}${_&&ie` ${ie.identifier(_)}`}${a}`)}else t.push(ie`${ie.raw(n.joinType)} join${o} ${s}${a}`);i<e.length-1&&t.push(ie` `)}return ie.join(t)}buildFromTable(e){if(r(e,R)&&e[R.Symbol.IsAlias]){let t=ie`${ie.identifier(e[R.Symbol.OriginalName])}`;return e[R.Symbol.Schema]&&(t=ie`${ie.identifier(e[R.Symbol.Schema])}.${t}`),ie`${t} ${ie.identifier(e[R.Symbol.Name])}`}return e}buildSelectQuery({withList:e,fields:t,fieldsFlat:i,where:n,having:s,table:o,joins:a,orderBy:l,groupBy:u,limit:d,offset:c,lockingClause:m,distinct:p,setOperators:g}){const h=i??he(t);for(const e of h)if(r(e.field,_)&&M(e.field.table)!==(r(o,z)?o._.alias:r(o,qn)?o[L].name:r(o,Y)?void 0:M(o))&&!(e=>a?.some(({alias:t})=>t===(e[R.Symbol.IsAlias]?M(e):e[R.Symbol.BaseName])))(e.field.table)){const t=M(e.field.table);throw new Error(`Your "${e.path.join("->")}" field references a column "${t}"."${e.field.name}", but the table "${t}" is not part of the query! Did you forget to join it?`)}const f=!a||0===a.length,y=this.buildWithCTE(e);let b;p&&(b=!0===p?ie` distinct`:ie` distinct on (${ie.join(p.on,ie`, `)})`);const v=this.buildSelection(h,{isSingleTable:f}),w=this.buildFromTable(o),N=this.buildJoins(a),k=n?ie` where ${n}`:void 0,S=s?ie` having ${s}`:void 0;let x,C;l&&l.length>0&&(x=ie` order by ${ie.join(l,ie`, `)}`),u&&u.length>0&&(C=ie` group by ${ie.join(u,ie`, `)}`);const q="object"==typeof d||"number"==typeof d&&d>=0?ie` limit ${d}`:void 0,T=c?ie` offset ${c}`:void 0,j=ie.empty();if(m){const e=ie` for ${ie.raw(m.strength)}`;m.config.of&&e.append(ie` of ${ie.join(Array.isArray(m.config.of)?m.config.of:[m.config.of],ie`, `)}`),m.config.noWait?e.append(ie` nowait`):m.config.skipLocked&&e.append(ie` skip locked`),j.append(e)}const $=ie`${y}select${b} ${v} from ${w}${N}${k}${C}${S}${x}${q}${T}${j}`;return g.length>0?this.buildSetOperations($,g):$}buildSetOperations(e,t){const[i,...n]=t;if(!i)throw new Error("Cannot pass undefined values to any set operator");return 0===n.length?this.buildSetOperationQuery({leftSelect:e,setOperator:i}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:i}),n)}buildSetOperationQuery({leftSelect:e,setOperator:{type:t,isAll:i,rightSelect:n,limit:s,orderBy:o,offset:a}}){const _=ie`(${e.getSQL()}) `,l=ie`(${n.getSQL()})`;let u;if(o&&o.length>0){const e=[];for(const t of o)if(r(t,S))e.push(ie.identifier(t.name));else if(r(t,Y)){for(let e=0;e<t.queryChunks.length;e++){const i=t.queryChunks[e];r(i,S)&&(t.queryChunks[e]=ie.identifier(i.name))}e.push(ie`${t}`)}else e.push(ie`${t}`);u=ie` order by ${ie.join(e,ie`, `)} `}const d="object"==typeof s||"number"==typeof s&&s>=0?ie` limit ${s}`:void 0,c=ie.raw(`${t} ${i?"all ":""}`);return ie`${_}${c}${l}${u}${d}${a?ie` offset ${a}`:void 0}`}buildInsertQuery({table:e,values:t,onConflict:i,returning:n,withList:s,select:o,overridingSystemValue_:a}){const _=[],l=e[R.Symbol.Columns],u=Object.entries(l).filter(([e,t])=>!t.shouldDisableInsert()),d=u.map(([,e])=>ie.identifier(this.casing.getColumnCasing(e)));if(o){const e=t;r(e,Y)?_.push(e):_.push(e.getSQL())}else{const e=t;_.push(ie.raw("values "));for(const[t,i]of e.entries()){const n=[];for(const[e,t]of u){const s=i[e];if(void 0===s||r(s,te)&&void 0===s.value)if(void 0!==t.defaultFn){const e=t.defaultFn(),i=r(e,Y)?e:ie.param(e,t);n.push(i)}else if(t.default||void 0===t.onUpdateFn)n.push(ie`default`);else{const e=t.onUpdateFn(),i=r(e,Y)?e:ie.param(e,t);n.push(i)}else n.push(s)}_.push(n),t<e.length-1&&_.push(ie`, `)}}const c=this.buildWithCTE(s),m=ie.join(_);return ie`${c}insert into ${e} ${d} ${!0===a?ie`overriding system value `:void 0}${m}${i?ie` on conflict ${i}`:void 0}${n?ie` returning ${this.buildSelection(n,{isSingleTable:!0})}`:void 0}`}buildRefreshMaterializedViewQuery({view:e,concurrently:t,withNoData:i}){return ie`refresh materialized view${t?ie` concurrently`:void 0} ${e}${i?ie` with no data`:void 0}`}prepareTyping(e){return r(e,ct)||r(e,lt)?"json":r(e,Ct)?"decimal":r(e,ai)?"time":r(e,li)||r(e,di)?"timestamp":r(e,Re)||r(e,We)?"date":r(e,pi)?"uuid":"none"}sqlToQuery(e,t){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,prepareTyping:this.prepareTyping,invokeSource:t})}buildRelationalQueryWithoutPK({fullSchema:e,schema:t,tableNamesMap:i,table:n,tableConfig:s,queryConfig:o,tableAlias:a,nestedQueryRelation:l,joinOn:u}){let d,c,m,p=[],g=[];const h=[];if(!0===o){p=Object.entries(s.columns).map(([e,t])=>({dbKey:t.name,tsKey:e,field:ue(t,a),relationTableTsKey:void 0,isJson:!1,selection:[]}))}else{const n=Object.fromEntries(Object.entries(s.columns).map(([e,t])=>[e,ue(t,a)]));if(o.where){const e="function"==typeof o.where?o.where(n,{and:tn,between:gn,eq:Xi,exists:mn,gt:on,gte:an,ilike:bn,inArray:ln,isNull:dn,isNotNull:cn,like:fn,lt:rn,lte:_n,ne:en,not:sn,notBetween:hn,notExists:pn,notLike:yn,notIlike:vn,notInArray:un,or:nn,sql:ie}):o.where;m=e&&ce(e,a)}const l=[];let u=[];if(o.columns){let e=!1;for(const[t,i]of Object.entries(o.columns))void 0!==i&&t in s.columns&&(e||!0!==i||(e=!0),u.push(t));u.length>0&&(u=e?u.filter(e=>!0===o.columns?.[e]):Object.keys(s.columns).filter(e=>!u.includes(e)))}else u=Object.keys(s.columns);for(const e of u){const t=s.columns[e];l.push({tsKey:e,value:t})}let f,y=[];if(o.with&&(y=Object.entries(o.with).filter(e=>!!e[1]).map(([e,t])=>({tsKey:e,queryConfig:t,relation:s.relations[e]}))),o.extras){f="function"==typeof o.extras?o.extras(n,{sql:ie}):o.extras;for(const[e,t]of Object.entries(f))l.push({tsKey:e,value:de(t,a)})}for(const{tsKey:e,value:t}of l)p.push({dbKey:r(t,Y.Aliased)?t.fieldAlias:s.columns[e].name,tsKey:e,field:r(t,_)?ue(t,a):t,relationTableTsKey:void 0,isJson:!1,selection:[]});let b="function"==typeof o.orderBy?o.orderBy(n,{sql:ie,asc:wn,desc:Nn}):o.orderBy??[];Array.isArray(b)||(b=[b]),g=b.map(e=>r(e,_)?ue(e,a):ce(e,a)),d=o.limit,c=o.offset;for(const{tsKey:n,queryConfig:s,relation:o}of y){const _=Cn(t,i,o),l=i[W(o.referencedTable)],u=`${a}_${n}`,d=tn(..._.fields.map((e,t)=>Xi(ue(_.references[t],u),ue(e,a)))),c=this.buildRelationalQueryWithoutPK({fullSchema:e,schema:t,tableNamesMap:i,table:e[l],tableConfig:t[l],queryConfig:r(o,Sn)?!0===s?{limit:1}:{...s,limit:1}:s,tableAlias:u,joinOn:d,nestedQueryRelation:o}),m=ie`${ie.identifier(u)}.${ie.identifier("data")}`.as(n);h.push({on:ie`true`,table:new z(c.sql,{},u),alias:u,joinType:"left",lateral:!0}),p.push({dbKey:n,tsKey:n,field:m,relationTableTsKey:l,isJson:!0,selection:c.selection})}}if(0===p.length)throw new Yi({message:`No fields selected for table "${s.tsName}" ("${a}")`});let f;if(m=tn(u,m),l){let e=ie`json_build_array(${ie.join(p.map(({field:e,tsKey:t,isJson:i})=>i?ie`${ie.identifier(`${a}_${t}`)}.${ie.identifier("data")}`:r(e,Y.Aliased)?e.sql:e),ie`, `)})`;r(l,xn)&&(e=ie`coalesce(json_agg(${e}${g.length>0?ie` order by ${ie.join(g,ie`, `)}`:void 0}), '[]'::json)`);const t=[{dbKey:"data",tsKey:"data",field:e.as("data"),isJson:!0,relationTableTsKey:s.tsName,selection:p}];void 0!==d||void 0!==c||g.length>0?(f=this.buildSelectQuery({table:le(n,a),fields:{},fieldsFlat:[{path:[],field:ie.raw("*")}],where:m,limit:d,offset:c,orderBy:g,setOperators:[]}),m=void 0,d=void 0,c=void 0,g=[]):f=le(n,a),f=this.buildSelectQuery({table:r(f,Di)?f:new z(f,{},a),fields:{},fieldsFlat:t.map(({field:e})=>({path:[],field:r(e,_)?ue(e,a):e})),joins:h,where:m,limit:d,offset:c,orderBy:g,setOperators:[]})}else f=this.buildSelectQuery({table:le(n,a),fields:{},fieldsFlat:p.map(({field:e})=>({path:[],field:r(e,_)?ue(e,a):e})),joins:h,where:m,limit:d,offset:c,orderBy:g,setOperators:[]});return{tableTsKey:s.tsName,sql:f,selection:p}}}class jn{static[a]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class $n{static[a]="PgSelectBuilder";fields;session;dialect;withList=[];distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,e.withList&&(this.withList=e.withList),this.distinct=e.distinct}authToken;setToken(e){return this.authToken=e,this}from(e){const t=!!this.fields,i=e;let n;return n=this.fields?this.fields:r(i,z)?Object.fromEntries(Object.keys(i._.selectedFields).map(e=>[e,i[e]])):r(i,qn)?i[L].selectedFields:r(i,Y)?{}:ye(i),new Pn({table:i,fields:n,isPartialSelect:t,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct}).setToken(this.authToken)}}class An extends jn{static[a]="PgSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:i,session:n,dialect:s,withList:o,distinct:a}){super(),this.config={withList:o,table:e,fields:{...t},distinct:a,setOperators:[]},this.isPartialSelect=i,this.session=n,this.dialect=s,this._={selectedFields:t,config:this.config},this.tableName=be(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{};for(const t of Yn(e))this.usedTables.add(t)}getUsedTables(){return[...this.usedTables]}createJoin(e,t){return(i,n)=>{const s=this.tableName,o=be(i);for(const e of Yn(i))this.usedTables.add(e);if("string"==typeof o&&this.config.joins?.some(e=>e.alias===o))throw new Error(`Alias "${o}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof s&&(this.config.fields={[s]:this.config.fields}),"string"==typeof o&&!r(i,Y))){const e=r(i,z)?i._.selectedFields:r(i,ae)?i[L].selectedFields:i[R.Symbol.Columns];this.config.fields[o]=e}if("function"==typeof n&&(n=n(new Proxy(this.config.fields,new Pi({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:n,table:i,joinType:e,alias:o,lateral:t}),"string"==typeof o)switch(e){case"left":this.joinsNotNullableMap[o]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[o]=!0;break;case"cross":case"inner":this.joinsNotNullableMap[o]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[o]=!1}return this}}leftJoin=this.createJoin("left",!1);leftJoinLateral=this.createJoin("left",!0);rightJoin=this.createJoin("right",!1);innerJoin=this.createJoin("inner",!1);innerJoinLateral=this.createJoin("inner",!0);fullJoin=this.createJoin("full",!1);crossJoin=this.createJoin("cross",!1);crossJoinLateral=this.createJoin("cross",!0);createSetOperator(e,t){return i=>{const n="function"==typeof i?i(zn()):i;if(!fe(this.getSelectedFields(),n.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:n}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);intersectAll=this.createSetOperator("intersect",!0);except=this.createSetOperator("except",!1);exceptAll=this.createSetOperator("except",!0);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new Pi({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new Pi({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){const t=e[0](new Proxy(this.config.fields,new Pi({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){const t=e[0](new Proxy(this.config.fields,new Pi({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}else{const t=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}for(e,t={}){return this.config.lockingClause={strength:e,config:t},this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){const{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){const t=[];if(t.push(...Yn(this.config.table)),this.config.joins)for(const e of this.config.joins)t.push(...Yn(e.table));return new Proxy(new z(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new Pi({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new Pi({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}$withCache(e){return this.cacheConfig=void 0===e?{config:{},enable:!0,autoInvalidate:!0}:!1===e?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}}class Pn extends An{static[a]="PgSelect";_prepare(e){const{session:t,config:i,dialect:n,joinsNotNullableMap:s,authToken:o,cacheConfig:a,usedTables:r}=this;if(!t)throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");const{fields:_}=i;return O.startActiveSpan("drizzle.prepareQuery",()=>{const i=he(_),l=t.prepareQuery(n.sqlToQuery(this.getSQL()),i,e,!0,void 0,{type:"select",tables:[...r]},a);return l.joinsNotNullableMap=s,l.setToken(o)})}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>O.startActiveSpan("drizzle.operation",()=>this._prepare().execute(e,this.authToken))}function Bn(e,t){return(i,n,...s)=>{const o=[n,...s].map(i=>({type:e,isAll:t,rightSelect:i}));for(const e of o)if(!fe(i.getSelectedFields(),e.rightSelect.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return i.addSetOperators(o)}}!function(e,t){for(const i of t)for(const t of Object.getOwnPropertyNames(i.prototype))"constructor"!==t&&Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(i.prototype,t)||Object.create(null))}(Pn,[Ai]);const zn=()=>({union:Dn,unionAll:On,intersect:Ln,intersectAll:In,except:Fn,exceptAll:Qn}),Dn=Bn("union",!1),On=Bn("union",!0),Ln=Bn("intersect",!1),In=Bn("intersect",!0),Fn=Bn("except",!1),Qn=Bn("except",!0);class Vn{static[a]="PgQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=r(e,Tn)?e:void 0,this.dialectConfig=r(e,Tn)?void 0:e}$with=(e,t)=>{const i=this;return{as:n=>("function"==typeof n&&(n=n(i)),new Proxy(new D(n.getSQL(),t??("getSelectedFields"in n?n.getSelectedFields()??{}:{}),e,!0),new Pi({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){const t=this;return{select:function(i){return new $n({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e})},selectDistinct:function(e){return new $n({fields:e??void 0,session:void 0,dialect:t.getDialect(),distinct:!0})},selectDistinctOn:function(e,i){return new $n({fields:i??void 0,session:void 0,dialect:t.getDialect(),distinct:{on:e}})}}}select(e){return new $n({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new $n({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}selectDistinctOn(e,t){return new $n({fields:t??void 0,session:void 0,dialect:this.getDialect(),distinct:{on:e}})}getDialect(){return this.dialect||(this.dialect=new Tn(this.dialectConfig)),this.dialect}}class En{constructor(e,t){this.name=e,this.schema=t}static[a]="PgDefaultViewBuilderCore";config={};with(e){return this.config.with=e,this}}class Kn extends En{static[a]="PgViewBuilder";as(e){"function"==typeof e&&(e=e(new Vn));const t=new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}),i=new Proxy(e.getSelectedFields(),t);return new Proxy(new Wn({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:i,query:e.getSQL().inlineParams()}}),t)}}class Un extends En{static[a]="PgManualViewBuilder";columns;constructor(e,t,i){super(e,i),this.columns=ye(Li(e,t))}existing(){return new Proxy(new Wn({pgConfig:void 0,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}as(e){return new Proxy(new Wn({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}}class Jn{constructor(e,t){this.name=e,this.schema=t}static[a]="PgMaterializedViewBuilderCore";config={};using(e){return this.config.using=e,this}with(e){return this.config.with=e,this}tablespace(e){return this.config.tablespace=e,this}withNoData(){return this.config.withNoData=!0,this}}class Rn extends Jn{static[a]="PgMaterializedViewBuilder";as(e){"function"==typeof e&&(e=e(new Vn));const t=new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}),i=new Proxy(e.getSelectedFields(),t);return new Proxy(new Gn({pgConfig:{with:this.config.with,using:this.config.using,tablespace:this.config.tablespace,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:i,query:e.getSQL().inlineParams()}}),t)}}class Mn extends Jn{static[a]="PgManualMaterializedViewBuilder";columns;constructor(e,t,i){super(e,i),this.columns=ye(Li(e,t))}existing(){return new Proxy(new Gn({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}as(e){return new Proxy(new Gn({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new Pi({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}}class Wn extends qn{static[a]="PgView";[Ri];constructor({pgConfig:e,config:t}){super(t),e&&(this[Ri]={with:e.with})}}const Hn=Symbol.for("drizzle:PgMaterializedViewConfig");class Gn extends qn{static[a]="PgMaterializedView";[Hn];constructor({pgConfig:e,config:t}){super(t),this[Hn]={with:e?.with,using:e?.using,tablespace:e?.tablespace,withNoData:e?.withNoData}}}function Yn(e){return r(e,Di)?[e[I]?`${e[I]}.${e[R.Symbol.BaseName]}`:e[R.Symbol.BaseName]]:r(e,z)?e._.usedTables??[]:r(e,Y)?e.usedTables??[]:[]}class Zn{constructor(e,t,i){this.seqName=e,this.seqOptions=t,this.schema=i}static[a]="PgSequence"}class Xn{constructor(e){this.schemaName=e}static[a]="PgSchema";table=(e,t,i)=>Oi(e,t,i,this.schemaName);view=(e,t)=>function(e,t,i){return t?new Un(e,t,i):new Kn(e,i)}(e,t,this.schemaName);materializedView=(e,t)=>function(e,t,i){return t?new Mn(e,t,i):new Rn(e,i)}(e,t,this.schemaName);enum(e,t){return Array.isArray(t)?function(e,t,i){const n=Object.assign(e=>new P(e??"",n),{enumName:e,enumValues:t,schema:i,[A]:!0});return n}(e,[...t],this.schemaName):function(e,t,i){const n=Object.assign(e=>new j(e??"",n),{enumName:e,enumValues:Object.values(t),schema:i,[A]:!0});return n}(e,t,this.schemaName)}sequence=(e,t)=>function(e,t,i){return new Zn(e,t,i)}(e,t,this.schemaName);getSQL(){return new Y([ie.identifier(this.schemaName)])}shouldOmitSQLParens(){return!0}}function es(e){if("public"===e)throw new Error("You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema");return new Xn(e)}const ts=es("raw"),is=es("rendered"),ns=es("internal");es("cached");const ss=ts.enum("state",["draft","published","expired"]),os=ts.enum("restriction_level",["ogl_compatible","ogl_equivalent","restricted","highly_restricted"]),as=ts.enum("media_provenance",["oak_created","oak_illustration","partner_created","creative_commons","pixabay","pexels","unsplash","openverse","freesvg","needpix","bridgeman","shutterstock","dall_e","adobe_firefly","other"]),rs=ts.enum("acquisition_basis",["oak_owned","public_domain","gratis","paid","creative_commons"]),_s=ts.enum("permission_status",["not_required","granted","denied"]),ls=ts.enum("territory",["uk","worldwide","worldwide_no_usa","other_territory"]),us=ts.enum("licence",["cc0","cc_by","cc_by_sa","cc_by_nc","cc_by_nc_sa","cc_by_nc_nd","cc_by_nd","ogl","unlimited_use","limited_use_permission_required","single_use_permission_required","other"]),ds=ts.enum("question_type",["explanatory-text","match","multiple-choice","order","short-answer","text"]),cs=ts.enum("tag_category",["discipline","domain","world_view"]),ms=ts.enum("media_kind",["video","sound"]),ps=ts.enum("clip_section",["intro","lesson_outline"]),gs=ts.enum("redirect_type",["301","302","307","308"]),hs=ts.enum("redirect_entity_source",["lessons","units","programmes","subjects"]),fs=ns.enum("operation",["insert","update","delete"]),ys=ns.enum("media_type_enum",["video","sound","gdrive_file","bucket_file"]),bs=ns.enum("lesson_component_type_enum",["document","downloadable","lesson_video","media_clip","quiz"]),vs={created_at:ci("created_at",{withTimezone:!0}).defaultNow(),updated_at:ci("updated_at",{withTimezone:!0}).$onUpdateFn(()=>new Date)},ws={created_at:ci("created_at",{withTimezone:!0}).notNull().defaultNow()},Ns=ns.enum("release_type",["mathfix","migration"]),ks=ns.table("releases",{release_id:st("release_id").primaryKey().generatedByDefaultAsIdentity(),_authoring_state:ss("_authoring_state").notNull(),approved:ze("approved").notNull().default(!1),approver:mt("approver"),description:si("description"),estimated_release_date:He("estimated_release_date"),locked:ze("locked").notNull().default(!1),name:si("name"),notes:si("notes"),release_type:Ns("release_type"),release_uid:Le("release_uid",{length:16}),...vs}),Ss={_state:ss("_state").notNull()},xs={_authoring_state:ss("_authoring_state").notNull()},Cs={_choice_state:ss("_choice_state").notNull()},qs={_lesson_state:ss("_lesson_state").notNull()},Ts={_programme_state:ss("_programme_state").notNull()},js={_question_state:ss("_question_state").notNull()},$s={_quiz_state:ss("_quiz_state").notNull()},As={_subject_phase_state:ss("_subject_phase_state").notNull()},Ps={_thread_state:ss("_thread_state").notNull()},Bs={_unit_state:ss("_unit_state").notNull()},zs={_unit_variant_state:ss("_unit_variant_state").notNull()},Ds={_works_copyright_state:ss("_works_copyright_state").notNull()},Os={_choice_state:ss("_choice_state")},Ls={_unit_variant_state:ss("_unit_variant_state")},Is=({name:e,columnA:t,columnB:n})=>ge(e,i.sql`${t} = 'expired' or ${n} = 'expired' or ${t} = ${n}`),Fs=({name:e,columnA:t,columnB:n})=>ge(e,i.sql`${t} = 'expired' or ${n} is null or ${n} = 'expired' or ${t} = ${n}`),Qs=({name:e,columnA:t,columnB:n,allow:s})=>ge(e,i.sql.join([i.sql`${t} = 'expired'`,i.sql`${n} = 'expired'`,i.sql`${t} = ${n}`,...s.map(([e,s])=>i.sql`(${t} = ${i.sql.raw(`'${e}'`)} and ${n} = ${i.sql.raw(`'${s}'`)})`)],i.sql` or `)),Vs={_expire_on_release:ze("_expire_on_release").notNull().default(!1),_release_id:st("_release_id").references(()=>ks.release_id)},Es=Ss,Ks=ts.table("gdrive_files",{gdrive_file_id:st("gdrive_file_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),epoch:si("epoch"),google_drive_id:si("google_drive_id"),google_drive_url:si("google_drive_url"),opendocument_presentation_bucket_name:si("opendocument_presentation_bucket_name"),opendocument_presentation_bucket_path:si("opendocument_presentation_bucket_path"),opendocument_text_bucket_name:si("opendocument_text_bucket_name"),opendocument_text_bucket_path:si("opendocument_text_bucket_path"),pdf_bucket_name:si("pdf_bucket_name"),pdf_bucket_path:si("pdf_bucket_path"),powerpoint_bucket_name:si("powerpoint_bucket_name"),powerpoint_bucket_path:si("powerpoint_bucket_path"),previous_document_id:st("previous_document_id"),word_bucket_name:si("word_bucket_name"),word_bucket_path:si("word_bucket_path"),...Vs,...vs}),Us=ts.table("lessons",{lesson_id:st("lesson_id").notNull().generatedByDefaultAsIdentity(),...Es,agf__has_copyright_restrictions:ze("agf__has_copyright_restrictions"),agf__restricted_download:ze("agf__restricted_download"),deprecated_fields:mt("deprecated_fields"),equipment_and_resources:mt("equipment_and_resources"),has_tag_practical_not_remote:ze("has_tag_practical_not_remote").notNull().default(!1),is_sensitive:ze("is_sensitive").notNull().default(!1),key_learning_points:mt("key_learning_points"),keywords:mt("keywords"),lesson_outline:mt("lesson_outline"),lesson_uid:Le("lesson_uid",{length:16}).notNull(),misconceptions_and_common_mistakes:mt("misconceptions_and_common_mistakes"),phonics_outcome:si("phonics_outcome"),pupil_lesson_outcome:si("pupil_lesson_outcome"),slug:si("slug").notNull(),teacher_tips:mt("teacher_tips"),title:si("title").notNull(),...Vs,...vs},e=>[Ki({columns:[e.lesson_id,e._state]}),p("lessons_slug_unique").on(e.slug,e._state)]),Js=ts.enum("document_type",["slidedeck","worksheet","worksheet_answers","supplementary_resource","lesson_guide"]);ts.table("documents",{document_id:st("document_id").notNull().generatedByDefaultAsIdentity(),...Es,gdrive_file_id:st("gdrive_file_id").notNull(),lesson_id:st("lesson_id"),deprecated_fields:mt("deprecated_fields"),document_type:Js("document_type").notNull(),document_uid:Le("document_uid",{length:16}),previous_lesson_id:st("previous_lesson_id"),...Vs,...vs},e=>[Ki({columns:[e.document_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"documents_gdrive_file_fk",columns:[e.gdrive_file_id],foreignColumns:[Ks.gdrive_file_id]}),p().on(e.lesson_id,e.document_type,e._state)]);const Rs=ts.table("bucket_files",{bucket_file_id:st("bucket_file_id").primaryKey().generatedByDefaultAsIdentity(),...xs,bucket_name:si("bucket_name"),bucket_path:si("bucket_path"),byte_size:st("byte_size"),cloudinary_public_id:si("cloudinary_public_id"),cloudinary_source_url:si("cloudinary_source_url"),content_type:si("content_type"),deprecated_fields:mt("deprecated_fields"),filename:si("filename"),media_description:si("media_description"),name:si("name"),previous_downloadable_id:st("previous_downloadable_id"),...Vs,...vs},e=>[p("bucket_files_cloudinary_public_id_unique").on(e.cloudinary_public_id)]);ts.table("downloadables",{downloadable_id:st("downloadable_id").notNull().generatedByDefaultAsIdentity(),...Es,bucket_file_id:st("bucket_file_id").notNull(),lesson_id:st("lesson_id"),custom_title:si("custom_title"),deprecated_fields:mt("deprecated_fields"),position:st("position").notNull(),previous_lesson_id:st("previous_lesson_id"),...Vs,...vs},e=>[Ki({columns:[e.downloadable_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"downloadables_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rs.bucket_file_id]}),Ei("downloadables_lesson_position_unique").on(e.lesson_id,e.position,e._state)]);const Ms=ts.table("videos",{video_id:st("video_id").primaryKey().generatedByDefaultAsIdentity(),...xs,cloudinary_public_id:si("cloudinary_public_id"),cloudinary_source_url:si("cloudinary_source_url"),contains_identifiable_face:ze("contains_identifiable_face"),deprecated_fields:mt("deprecated_fields"),duration_seconds:At("duration_seconds"),has_bsl:ze("has_bsl"),media_description:si("media_description"),mux_asset_id:si("mux_asset_id"),mux_playback_id:si("mux_playback_id"),name:si("name"),previous_lesson_video_id:st("previous_lesson_video_id"),previous_media_clip_ids:st("previous_media_clip_ids").array(),raw_mux_data:mt("raw_mux_data"),signed_stream_id:si("signed_stream_id"),title:si("title"),url:si("url"),video_uid:Le("video_uid",{length:16}),...Vs,...vs},e=>[p("videos_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("videos_cloudinary_source_url_unique").on(e.cloudinary_source_url)]);ts.table("lesson_videos",{lesson_video_id:st("lesson_video_id").notNull().generatedByDefaultAsIdentity(),...Es,lesson_id:st("lesson_id"),sign_language_video_id:st("sign_language_video_id"),video_id:st("video_id"),previous_lesson_id:st("previous_lesson_id"),...Vs,...vs},e=>[Ki({columns:[e.lesson_video_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({columns:[e.video_id],foreignColumns:[Ms.video_id]}),m({name:"lesson_videos_sign_lang_video_fk",columns:[e.sign_language_video_id],foreignColumns:[Ms.video_id]}),Ei("lesson_videos_lesson_unique").on(e.lesson_id,e._state),ge("lesson_videos_video_required_published",i.sql`${e._state} <> 'published' or ${e.video_id} is not null`)]);const Ws=ts.table("media_clip_collection",{media_clip_collection_id:st("media_clip_collection_id").notNull().generatedByDefaultAsIdentity(),...Es,lesson_id:st("lesson_id"),previous_lesson_id:st("previous_lesson_id"),...Vs,...vs},e=>[Ki({columns:[e.media_clip_collection_id,e._state]}),m({name:"mc_collection_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),Ei("media_clip_collection_lesson_unique").on(e.lesson_id,e._state)]),Hs=ts.table("sounds",{sound_id:st("sound_id").primaryKey().generatedByDefaultAsIdentity(),...xs,cloudinary_public_id:si("cloudinary_public_id"),cloudinary_source_url:si("cloudinary_source_url"),duration_seconds:At("duration_seconds"),media_description:si("media_description"),mux_asset_id:si("mux_asset_id"),mux_playback_id:si("mux_playback_id"),name:si("name"),previous_media_clip_ids:st("previous_media_clip_ids").array(),title:si("title"),...Vs,...vs},e=>[p("sounds_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("sounds_cloudinary_source_url_unique").on(e.cloudinary_source_url)]);ts.table("media_clips",{media_clip_id:st("media_clip_id").notNull().generatedByDefaultAsIdentity(),...Es,media_clip_collection_id:st("media_clip_collection_id").notNull(),sound_id:st("sound_id"),video_id:st("video_id"),clip_section:ps("clip_section").notNull(),custom_title:si("custom_title"),lesson_outline_index:st("lesson_outline_index"),media_kind:ms("media_kind"),position:st("position").notNull(),...Vs,...vs},e=>[Ki({columns:[e.media_clip_id,e._state]}),m({name:"media_clips_mc_collection_fk",columns:[e.media_clip_collection_id,e._state],foreignColumns:[Ws.media_clip_collection_id,Ws._state]}),m({columns:[e.sound_id],foreignColumns:[Hs.sound_id]}),m({columns:[e.video_id],foreignColumns:[Ms.video_id]}),ge("media_clip_video_or_sound",i.sql`(video_id IS NOT NULL AND sound_id IS NULL) OR (video_id IS NULL AND sound_id IS NOT NULL)`),ge("media_clip_section_lesson_outline",i.sql`(clip_section = 'lesson_outline' AND lesson_outline_index IS NOT NULL)
|
|
8
|
-
OR (clip_section = 'intro' AND lesson_outline_index IS NULL)`),Ei("media_clips_lo_position_unique").on(e.media_clip_collection_id,e.lesson_outline_index,e.position,e._state).where(i.sql`${e.clip_section} = 'lesson_outline'`),Ei("media_clips_intro_position_unique").on(e.media_clip_collection_id,e.position,e._state).where(i.sql`${e.clip_section} = 'intro'`)]);const Gs=ts.table("images",{image_id:st("image_id").primaryKey().generatedByDefaultAsIdentity(),...xs,cloudinary_public_id:si("cloudinary_public_id"),cloudinary_source_url:si("cloudinary_source_url"),contains_identifiable_face:ze("contains_identifiable_face"),height:st("height"),media_description:si("media_description"),name:si("name"),width:st("width"),...Vs,...vs},e=>[p("images_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("images_cloudinary_source_url_unique").on(e.cloudinary_source_url)]),Ys=ts.table("questions",{question_id:st("question_id").notNull().generatedByDefaultAsIdentity(),...Es,stem_image_id:st("stem_image_id"),deprecated_fields:mt("deprecated_fields"),feedback:si("feedback"),hint:si("hint"),question_type:ds("question_type").notNull(),question_uid:Le("question_uid",{length:16}).notNull(),stem_text:si("stem_text"),...Vs,...vs},e=>[Ki({columns:[e.question_id,e._state]}),m({columns:[e.stem_image_id],foreignColumns:[Gs.image_id]})]);ts.table("question_options",{option_id:st("option_id").notNull().generatedByDefaultAsIdentity(),...Es,body_image_id:st("body_image_id"),match_partner_image_id:st("match_partner_image_id"),question_id:st("question_id").notNull(),body_text:si("body_text"),correct_order:st("correct_order"),is_default:ze("is_default"),is_correct:ze("is_correct"),match_partner_text:si("match_partner_text"),position:st("position"),temporary_fields:mt("temporary_fields"),...Vs,...vs},e=>[Ki({columns:[e.option_id,e._state]}),m({name:"question_options_question_fk",columns:[e.question_id,e._state],foreignColumns:[Ys.question_id,Ys._state]}),m({name:"question_options_body_image_fk",columns:[e.body_image_id],foreignColumns:[Gs.image_id]}),m({name:"question_options_match_partner_image_fk",columns:[e.match_partner_image_id],foreignColumns:[Gs.image_id]})]);const Zs=ts.table("units",{unit_id:st("unit_id").notNull().generatedByDefaultAsIdentity(),...Ss,deprecated_fields:mt("deprecated_fields"),description:si("description").notNull(),slug:si("slug"),title:si("title").notNull(),unit_uid:Le("unit_uid",{length:16}),why_this_why_now:si("why_this_why_now"),...Vs,...vs},e=>[Ki({columns:[e.unit_id,e._state]})]);ts.table("question_units",{question_id:st("question_id").notNull(),unit_id:st("unit_id").notNull(),...js,...Bs,...Vs,...vs},e=>[Ki({name:"question_units_pk",columns:[e.question_id,e.unit_id,e._question_state,e._unit_state]}),m({name:"question_units_question_fk",columns:[e.question_id,e._question_state],foreignColumns:[Ys.question_id,Ys._state]}),m({name:"question_units_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zs.unit_id,Zs._state]}),Is({name:"question_units_state_coherence",columnA:e._question_state,columnB:e._unit_state})]);const Xs=ts.enum("quiz_role",["starter","exit"]),eo=ts.table("quizzes",{quiz_id:st("quiz_id").notNull().generatedByDefaultAsIdentity(),...Es,lesson_id:st("lesson_id"),deprecated_fields:mt("deprecated_fields"),previous_lesson_id:st("previous_lesson_id"),quiz_answers_pdf_bucket_name:si("quiz_answers_pdf_bucket_name"),quiz_answers_pdf_bucket_path:si("quiz_answers_pdf_bucket_path"),quiz_pdf_bucket_name:si("quiz_pdf_bucket_name"),quiz_pdf_bucket_path:si("quiz_pdf_bucket_path"),quiz_role:Xs("quiz_role").notNull(),quiz_uid:Le("quiz_uid",{length:16}).notNull(),...Vs,...vs},e=>[Ki({columns:[e.quiz_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),Ei("quizzes_lesson_role_unique").on(e.lesson_id,e.quiz_role,e._state)]);ts.table("quiz_questions",{quiz_id:st("quiz_id").notNull(),question_id:st("question_id").notNull(),...$s,...js,position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"quiz_questions_pk",columns:[e.quiz_id,e.question_id,e._quiz_state,e._question_state]}),m({name:"quiz_questions_quiz_fk",columns:[e.quiz_id,e._quiz_state],foreignColumns:[eo.quiz_id,eo._state]}),m({name:"quiz_questions_question_fk",columns:[e.question_id,e._question_state],foreignColumns:[Ys.question_id,Ys._state]}),Is({name:"quiz_questions_state_coherence",columnA:e._quiz_state,columnB:e._question_state})]);const to=ts.table("urls",{url_id:st("url_id").primaryKey().generatedByDefaultAsIdentity(),...xs,cloudinary_public_id:si("cloudinary_public_id"),cloudinary_source_url:si("cloudinary_source_url"),name:si("name"),url:si("url"),...Vs,...vs},e=>[p("urls_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("urls_cloudinary_source_url_unique").on(e.cloudinary_source_url)]),io=ts.table("media_copyright",{media_copyright_id:st("media_copyright_id").notNull().generatedByDefaultAsIdentity(),...Es,bucket_file_id:st("bucket_file_id"),image_id:st("image_id"),sound_id:st("sound_id"),url_id:st("url_id"),video_id:st("video_id"),acquisition_basis:rs("acquisition_basis"),additional_restrictions:si("additional_restrictions"),attribution:si("attribution"),deprecated_fields:mt("deprecated_fields"),internal_notes:si("internal_notes"),legacy_data_shape:ze("legacy_data_shape").notNull(),licence:us("licence"),media_copyright_uid:Le("media_copyright_uid",{length:16}).notNull(),media_provenance:as("media_provenance"),media_provenance_url:si("media_provenance_url"),permission_status:_s("permission_status"),restriction_level_override:os("restriction_level_override"),territory_other:si("territory_other"),territory_override:ls("territory_override"),third_party_id:si("third_party_id"),...Vs,...vs},e=>[Ki({columns:[e.media_copyright_id,e._state]}),m({columns:[e.image_id],foreignColumns:[Gs.image_id]}),m({columns:[e.sound_id],foreignColumns:[Hs.sound_id]}),m({columns:[e.video_id],foreignColumns:[Ms.video_id]}),m({name:"media_copyright_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rs.bucket_file_id]}),m({columns:[e.url_id],foreignColumns:[to.url_id]}),ge("media_copyright_has_exactly_one_media",i.sql`(image_id IS NOT NULL)::int + (sound_id IS NOT NULL)::int + (video_id IS NOT NULL)::int + (bucket_file_id IS NOT NULL)::int + (url_id IS NOT NULL)::int = 1`),p("media_copyright_image_unique").on(e.image_id,e._state),p("media_copyright_sound_unique").on(e.sound_id,e._state),p("media_copyright_video_unique").on(e.video_id,e._state),p("media_copyright_bucket_file_unique").on(e.bucket_file_id,e._state),p("media_copyright_url_unique").on(e.url_id,e._state),p("media_copyright_uid_unique").on(e.media_copyright_uid,e._state)]),no=ns.enum("contract_territory",["worldwide","worldwide_excl_usa","worldwide_excl_canada_and_usa","uk_only","uk_and_commonwealth","uk_and_commonwealth_excl_canada","uk_and_eire"]),so=ns.table("tpc_contracts",{tpc_contract_id:st("tpc_contract_id").primaryKey().generatedByDefaultAsIdentity(),...xs,effective_date:He("effective_date"),end_date:He("end_date"),geo_restricted:ze().notNull().default(!1),juro_id:si("juro_id").notNull(),juro_url:si("juro_url"),login_required:ze().notNull().default(!1),name:si("name").notNull(),raw_contract:mt("raw_contract"),restricted_download:ze().notNull().default(!1),restriction_level:os(),signing_side:si("signing_side"),territory:no("territory"),tpc_contract_uid:Le("tpc_contract_uid",{length:16}).notNull(),...vs},()=>[]);ts.table("media_copyright_tpc_contracts",{media_copyright_id:st("media_copyright_id").notNull(),tpc_contract_id:st("tpc_contract_id").notNull(),...Es,...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"media_copyright_tpc_contracts_pk",columns:[e.media_copyright_id,e.tpc_contract_id,e._state]}),m({name:"media_copyright_tpc_contract_media_copyright_fk",columns:[e.media_copyright_id,e._state],foreignColumns:[io.media_copyright_id,io._state]}),m({name:"media_copyright_tpc_contract_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[so.tpc_contract_id]}),m({name:"media_copyright_tpc_contracts_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]})]),ts.table("gdrive_file_images",{gdrive_file_id:st("gdrive_file_id").notNull(),image_id:st("image_id").notNull(),...xs,...Vs,...vs},e=>[Ki({columns:[e.gdrive_file_id,e.image_id]}),m({name:"gdrive_file_images_gdrive_file_fk",columns:[e.gdrive_file_id],foreignColumns:[Ks.gdrive_file_id]}),m({columns:[e.image_id],foreignColumns:[Gs.image_id]})]),ts.table("lesson_media",{lesson_media_id:st("lesson_media_id").notNull().generatedByDefaultAsIdentity(),...Ss,lesson_id:st("lesson_id").notNull(),bucket_file_id:st("bucket_file_id"),image_id:st("image_id"),sound_id:st("sound_id"),url_id:st("url_id"),video_id:st("video_id"),...Vs,...vs},e=>[Ki({name:"lesson_media_pk",columns:[e.lesson_media_id,e._state]}),m({name:"lesson_media_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"lesson_media_image_fk",columns:[e.image_id],foreignColumns:[Gs.image_id]}),m({name:"lesson_media_sound_fk",columns:[e.sound_id],foreignColumns:[Hs.sound_id]}),m({name:"lesson_media_video_fk",columns:[e.video_id],foreignColumns:[Ms.video_id]}),m({name:"lesson_media_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rs.bucket_file_id]}),m({name:"lesson_media_url_fk",columns:[e.url_id],foreignColumns:[to.url_id]}),ge("lesson_media_has_exactly_one_media",i.sql`(image_id IS NOT NULL)::int + (sound_id IS NOT NULL)::int + (video_id IS NOT NULL)::int + (bucket_file_id IS NOT NULL)::int + (url_id IS NOT NULL)::int = 1`),p("lesson_media_lesson_asset_unique").on(e.lesson_id,e._state,e.image_id,e.sound_id,e.video_id,e.bucket_file_id,e.url_id).nullsNotDistinct()]);const oo=ts.table("works_copyright",{works_copyright_id:st("works_copyright_id").notNull().generatedByDefaultAsIdentity(),...Ss,attribution:si("attribution"),author:si("author"),deprecated_fields:mt("deprecated_fields"),raw_juro_data:mt("raw_juro_data"),restriction_level:os("restriction_level"),title:si("title"),works_copyright_uid:Le("works_copyright_uid",{length:16}),...Vs,...vs},e=>[Ki({columns:[e.works_copyright_id,e._state]})]);ts.table("lesson_works_copyright",{lesson_id:st("lesson_id").notNull(),works_copyright_id:st("works_copyright_id").notNull(),...qs,...Ds,...Vs,...vs},e=>[Ki({name:"lesson_works_copyright_pk",columns:[e.lesson_id,e.works_copyright_id,e._lesson_state,e._works_copyright_state]}),m({name:"lesson_works_copyright_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"lesson_works_copyright_works_copyright_fk",columns:[e.works_copyright_id,e._works_copyright_state],foreignColumns:[oo.works_copyright_id,oo._state]}),Qs({name:"lesson_works_copyright_state_coherence",columnA:e._lesson_state,columnB:e._works_copyright_state,allow:[["draft","published"]]})]);const ao=ts.table("features",{feature_id:st("feature_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key:si("key").notNull(),...Vs,...vs},e=>[p("features_key_unique").on(e.key)]);ts.table("lesson_features",{lesson_id:st("lesson_id").notNull(),feature_id:st("feature_id").notNull(),...Es,value:si("value"),...Vs,...vs},e=>[Ki({columns:[e.lesson_id,e.feature_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"lesson_features_feature_fk",columns:[e.feature_id],foreignColumns:[ao.feature_id]})]),ts.table("sound_transcripts",{sound_id:st("sound_id").notNull(),...Ss,bad_language_detected:ze("bad_language_detected"),deprecated_fields:mt("deprecated_fields"),inappropriate_words:mt("inappropriate_words"),language_approved:ze("language_approved"),transcript:si("transcript"),transcript_vtt_url:si("transcript_vtt_url"),...Vs,...vs},e=>[Ki({columns:[e.sound_id,e._state]}),m({columns:[e.sound_id],foreignColumns:[Hs.sound_id]})]),ts.table("video_captions",{video_id:st("video_id").notNull(),...Ss,bad_language_detected:ze("bad_language_detected"),deprecated_fields:mt("deprecated_fields"),inappropriate_words:mt("inappropriate_words"),language_approved:ze("language_approved"),transcript:si("transcript"),transcript_vtt_url:si("transcript_vtt_url"),...Vs,...vs},e=>[Ki({columns:[e.video_id,e._state]}),m({columns:[e.video_id],foreignColumns:[Ms.video_id]})]),ts.table("works_copyright_tpc_contracts",{works_copyright_id:st("works_copyright_id").notNull(),tpc_contract_id:st("tpc_contract_id").notNull(),...Es,...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"works_copyright_tpc_contracts_pk",columns:[e.works_copyright_id,e.tpc_contract_id,e._state]}),m({name:"works_copyright_tpc_contract_works_copyright_fk",columns:[e.works_copyright_id,e._state],foreignColumns:[oo.works_copyright_id,oo._state]}),m({name:"works_copyright_tpc_contract_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[so.tpc_contract_id]}),m({name:"works_copyright_tpc_contracts_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]})]),ts.table("videos_works_copyright",{video_id:st("video_id").notNull(),works_copyright_id:st("works_copyright_id").notNull(),...Ss,...Vs,...vs},e=>[Ki({columns:[e.video_id,e.works_copyright_id,e._state]}),m({name:"videos_works_copyright_video_fk",columns:[e.video_id],foreignColumns:[Ms.video_id]}),m({name:"videos_works_copyright_works_copyright_fk",columns:[e.works_copyright_id,e._state],foreignColumns:[oo.works_copyright_id,oo._state]})]);const ro=ts.table("supervision_levels",{supervision_level_id:st("supervision_level_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),supervision_level_rating:st("supervision_level_rating"),title:si("title").notNull(),...Vs,...vs}),_o=ts.table("content_guidance",{content_guidance_id:st("content_guidance_id").primaryKey().generatedByDefaultAsIdentity(),...xs,supervision_level_id:st("supervision_level_id").notNull(),content_guidance_area:si("content_guidance_area"),content_guidance_code:si("content_guidance_code"),content_guidance_description:si("content_guidance_description"),content_guidance_label:si("content_guidance_label"),deprecated_fields:mt("deprecated_fields"),...Vs,...vs},e=>[m({name:"content_guid_super_level_fk",columns:[e.supervision_level_id],foreignColumns:[ro.supervision_level_id]})]),lo=ts.table("key_stages",{key_stage_id:st("key_stage_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),key_stage:si("key_stage"),slug:si("slug"),...Vs,...vs}),uo=ts.table("phases",{phase_id:st("phase_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),phase:si("phase"),slug:si("slug"),...Vs,...vs}),co=ts.table("subjects",{subject_id:st("subject_id").primaryKey().generatedByDefaultAsIdentity(),...xs,subject_parent_id:st("subject_parent_id"),deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),non_curriculum:ze("non_curriculum"),slug:si("slug"),subject:si("subject"),...Vs,...vs},e=>[m({name:"subjects_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[e.subject_id]})]),mo=ts.table("years",{year_id:st("year_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key_stage_id:st("key_stage_id").notNull(),phase_id:st("phase_id").notNull(),deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),slug:si("slug"),year:si("year"),...Vs,...vs},e=>[m({columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({columns:[e.phase_id],foreignColumns:[uo.phase_id]})]);ts.table("content_guidance_scopes",{scope_id:st("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xs,content_guidance_id:st("content_guidance_id").notNull(),key_stage_id:st("key_stage_id"),phase_id:st("phase_id"),subject_id:st("subject_id"),subject_parent_id:st("subject_parent_id"),year_id:st("year_id"),...Vs,...vs},e=>[m({name:"content_guid_scopes_content_guid_fk",columns:[e.content_guidance_id],foreignColumns:[_o.content_guidance_id]}),m({name:"content_guid_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"content_guid_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[co.subject_id]}),m({name:"content_guid_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"content_guid_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]})]);const po=ts.table("exam_board_specs",{exam_board_spec_id:st("exam_board_spec_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),title:si("title").notNull(),...Vs,...vs});ts.table("exam_board_spec_scopes",{scope_id:st("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xs,exam_board_spec_id:st("exam_board_spec_id").notNull(),key_stage_id:st("key_stage_id"),phase_id:st("phase_id"),subject_id:st("subject_id"),subject_parent_id:st("subject_parent_id"),year_id:st("year_id"),...Vs,...vs},e=>[m({name:"exam_spec_scopes_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[po.exam_board_spec_id]}),m({name:"exam_spec_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"exam_spec_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[co.subject_id]}),m({name:"exam_spec_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"exam_spec_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]})]),ts.table("lesson_content_guidance",{lesson_id:st("lesson_id").notNull(),content_guidance_id:st("content_guidance_id").notNull(),...Es,position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"lesson_content_guid_pk",columns:[e.lesson_id,e.content_guidance_id,e._state]}),m({name:"lesson_content_guid_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({name:"lesson_content_guid_content_guid_fk",columns:[e.content_guidance_id],foreignColumns:[_o.content_guidance_id]})]);const go=ts.table("tags",{tag_id:st("tag_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),tag_category:cs("tag_category"),title:si("title").notNull(),...Vs,...vs});ts.table("lesson_tags",{lesson_id:st("lesson_id").notNull(),tag_id:st("tag_id").notNull(),...Es,position:st("position").notNull(),...Vs,...vs},e=>[Ki({columns:[e.lesson_id,e.tag_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Us.lesson_id,Us._state]}),m({columns:[e.tag_id],foreignColumns:[go.tag_id]})]);const ho=ts.table("national_curriculum",{national_curriculum_id:st("national_curriculum_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),title:si("title").notNull(),...Vs,...vs});ts.table("national_curriculum_scopes",{scope_id:st("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key_stage_id:st("key_stage_id"),national_curriculum_id:st("national_curriculum_id").notNull(),phase_id:st("phase_id"),subject_id:st("subject_id"),subject_parent_id:st("subject_parent_id"),year_id:st("year_id"),...Vs,...vs},e=>[m({name:"nat_curric_scopes_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[ho.national_curriculum_id]}),m({name:"nat_curric_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"nat_curric_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[co.subject_id]}),m({name:"nat_curric_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"nat_curric_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({name:"nat_curric_scopes_year_fk",columns:[e.year_id],foreignColumns:[mo.year_id]})]);const fo=ts.table("subject_categories",{subject_category_id:st("subject_category_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),slug:si("slug"),title:si("title").notNull(),...Vs,...vs});ts.table("subject_category_scopes",{scope_id:st("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key_stage_id:st("key_stage_id"),phase_id:st("phase_id"),subject_category_id:st("subject_category_id").notNull(),subject_id:st("subject_id"),subject_parent_id:st("subject_parent_id"),year_id:st("year_id"),...Vs,...vs},e=>[m({name:"subj_cat_scopes_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[fo.subject_category_id]}),m({name:"subj_cat_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"subj_cat_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[co.subject_id]}),m({name:"subj_cat_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"subj_cat_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]})]),ts.table("tag_scopes",{scope_id:st("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key_stage_id:st("key_stage_id"),phase_id:st("phase_id"),subject_id:st("subject_id"),subject_parent_id:st("subject_parent_id"),tag_id:st("tag_id").notNull(),year_id:st("year_id"),...Vs,...vs},e=>[m({columns:[e.tag_id],foreignColumns:[go.tag_id]}),m({columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"tag_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[co.subject_id]}),m({columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"tag_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]})]),ts.table("unit_exam_board_specs",{unit_id:st("unit_id").notNull(),exam_board_spec_id:st("exam_board_spec_id").notNull(),...Es,position:st("position").notNull(),...Vs,...vs},e=>[Ki({columns:[e.unit_id,e.exam_board_spec_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),m({name:"unit_exam_spec_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[po.exam_board_spec_id]})]),ts.table("unit_national_curriculum",{unit_id:st("unit_id").notNull(),national_curriculum_id:st("national_curriculum_id").notNull(),...Es,position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"unit_nat_curric_pk",columns:[e.unit_id,e.national_curriculum_id,e._state]}),m({name:"unit_nat_curric_unit_fk",columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),m({name:"unit_nat_curric_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[ho.national_curriculum_id]})]),ts.table("unit_subject_categories",{unit_id:st("unit_id").notNull(),subject_category_id:st("subject_category_id").notNull(),...Es,position:st("position").notNull(),...Vs,...vs},e=>[Ki({columns:[e.unit_id,e.subject_category_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),m({name:"unit_subj_cat_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[fo.subject_category_id]})]);const yo=ts.table("exam_boards",{exam_board_id:st("exam_board_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),exam_board:si("exam_board"),global_position:st("global_position").notNull(),slug:si("slug"),...Vs,...vs}),bo=ts.table("pathways",{pathway_id:st("pathway_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),pathway:si("pathway"),slug:si("slug"),...Vs,...vs}),vo=ts.table("tiers",{tier_id:st("tier_id").primaryKey().generatedByDefaultAsIdentity(),...xs,deprecated_fields:mt("deprecated_fields"),description:si("description"),global_position:st("global_position").notNull(),slug:si("slug"),tier:si("tier"),...Vs,...vs}),wo=ts.table("unit_variants",{unit_variant_id:st("unit_variant_id").notNull().generatedByDefaultAsIdentity(),...Es,exam_board_id:st("exam_board_id"),pathway_id:st("pathway_id"),subject_id:st("subject_id"),tier_id:st("tier_id"),unit_id:st("unit_id").notNull(),deprecated_fields:mt("deprecated_fields"),description_override:si("description_override"),optionality:si("optionality"),planned_number_of_lessons_override:st("planned_number_of_lessons_override"),prior_knowledge_requirements_override:si("prior_knowledge_requirements_override").array(),title_override:si("title_override"),unit_variant_uid:Le("unit_variant_uid",{length:16}),why_this_why_now_override:si("why_this_why_now_override"),...Vs,...vs},e=>[Ki({columns:[e.unit_variant_id,e._state]}),m({name:"unit_variants_exam_board_fk",columns:[e.exam_board_id],foreignColumns:[yo.exam_board_id]}),m({columns:[e.pathway_id],foreignColumns:[bo.pathway_id]}),m({columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({columns:[e.tier_id],foreignColumns:[vo.tier_id]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),p("unit_variants_unit_scope_unique").on(e.unit_id,e.subject_id,e.tier_id,e.exam_board_id,e.pathway_id,e.optionality,e._state).nullsNotDistinct()]);ts.table("unit_variant_exam_board_specs_override",{unit_variant_id:st("unit_variant_id").notNull(),exam_board_spec_id:st("exam_board_spec_id").notNull(),...Es,position:st("position").notNull(),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"unit_variant_exam_board_specs_override_pk",columns:[e.unit_variant_id,e.exam_board_spec_id,e._state]}),m({name:"unit_var_exam_spec_ovr_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"unit_var_exam_spec_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[wo.unit_variant_id,wo._state]}),m({name:"unit_var_exam_spec_ovr_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[po.exam_board_spec_id]})]),ts.table("unit_variant_national_curriculum_override",{unit_variant_id:st("unit_variant_id").notNull(),national_curriculum_id:st("national_curriculum_id").notNull(),...Es,position:st("position").notNull(),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"unit_variant_national_curriculum_override_pk",columns:[e.unit_variant_id,e.national_curriculum_id,e._state]}),m({name:"unit_var_nat_curric_ovr_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"unit_var_nat_curric_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[wo.unit_variant_id,wo._state]}),m({name:"unit_var_nat_curric_ovr_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[ho.national_curriculum_id]})]),ts.table("unit_variant_subject_categories_override",{unit_variant_id:st("unit_variant_id").notNull(),subject_category_id:st("subject_category_id").notNull(),...Es,position:st("position").notNull(),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"unit_variant_subject_categories_override_pk",columns:[e.unit_variant_id,e.subject_category_id,e._state]}),m({name:"unit_var_subj_cat_ovr_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"unit_var_subj_cat_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[wo.unit_variant_id,wo._state]}),m({name:"unit_var_subj_cat_ovr_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[fo.subject_category_id]})]);const No=ts.table("actions",{action_id:st("action_id").primaryKey().generatedByDefaultAsIdentity(),...xs,key:si("key").notNull(),...Vs,...vs},e=>[p("actions_key_unique").on(e.key)]),ko=ts.table("overrides_and_exceptions",{overrides_and_exceptions_id:st("overrides_and_exceptions_id").notNull().generatedByDefaultAsIdentity(),...Ss,description:si("description"),temporary_fields:mt("temporary_fields"),used_by_queries:mt("used_by_queries").notNull().default([]),...Vs,...vs},e=>[Ki({columns:[e.overrides_and_exceptions_id,e._state]})]);ts.table("overrides_and_exceptions_actions",{overrides_and_exceptions_id:st("overrides_and_exceptions_id").notNull(),action_id:st("action_id").notNull(),...Ss,value:mt("value").notNull(),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"ovr_exc_actions_pk",columns:[e.overrides_and_exceptions_id,e.action_id,e._state]}),m({name:"ovr_exc_actions_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"ovr_exc_actions_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[ko.overrides_and_exceptions_id,ko._state]}),m({name:"ovr_exc_actions_action_fk",columns:[e.action_id],foreignColumns:[No.action_id]})]),ts.table("overrides_and_exceptions_feature_scopes",{overrides_and_exceptions_id:st("overrides_and_exceptions_id").notNull(),condition_id:st("condition_id").notNull(),feature_id:st("feature_id").notNull(),...Ss,value:si("value").notNull(),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"ovr_exc_feature_scopes_pk",columns:[e.overrides_and_exceptions_id,e.condition_id,e.feature_id,e._state]}),m({name:"ovr_exc_feature_scopes_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"ovr_exc_feature_scopes_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[ko.overrides_and_exceptions_id,ko._state]}),m({name:"ovr_exc_feature_scopes_feature_fk",columns:[e.feature_id],foreignColumns:[ao.feature_id]})]),ts.table("overrides_and_exceptions_programme_scopes",{scope_id:st("scope_id").notNull().generatedByDefaultAsIdentity(),...Ss,key_stage_id:st("key_stage_id"),overrides_and_exceptions_id:st("overrides_and_exceptions_id").notNull(),pathway_id:st("pathway_id"),phase_id:st("phase_id"),subject_id:st("subject_id"),tier_id:st("tier_id"),legacy:ze("legacy"),subject_slug:si("subject_slug"),...Vs,_release_id:st("_release_id"),...vs},e=>[Ki({name:"ovr_exc_programme_scopes_pk",columns:[e.scope_id,e._state]}),m({name:"ovr_exc_programme_scopes_release_fk",columns:[e._release_id],foreignColumns:[ks.release_id]}),m({name:"ovr_exc_programme_scopes_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[ko.overrides_and_exceptions_id,ko._state]}),m({name:"ovr_exc_programme_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[lo.key_stage_id]}),m({name:"ovr_exc_programme_scopes_pathway_fk",columns:[e.pathway_id],foreignColumns:[bo.pathway_id]}),m({name:"ovr_exc_programme_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[uo.phase_id]}),m({name:"ovr_exc_programme_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({name:"ovr_exc_programme_scopes_tier_fk",columns:[e.tier_id],foreignColumns:[vo.tier_id]})]),ts.table("redirects",{entity_id:st("entity_id").notNull(),entity_source:hs("entity_source").notNull(),...Es,description:si("description"),redirect_entity_id:st("redirect_entity_id"),redirect_entity_source:hs("redirect_entity_source"),redirect_type:gs("redirect_type").notNull(),redirect_url:si("redirect_url"),...Vs,...vs},e=>[Ki({columns:[e.entity_id,e.entity_source,e._state]}),ge("redirect_has_exactly_one_target",i.sql`(redirect_url IS NOT NULL)::int + (redirect_entity_id IS NOT NULL)::int = 1`),ge("redirect_entity_ref_complete",i.sql`(redirect_entity_id IS NULL) = (redirect_entity_source IS NULL)`)]);const So=ts.table("choices",{choice_id:st("choice_id").notNull().generatedByDefaultAsIdentity(),...Es,unit_id:st("unit_id").notNull(),temporary_fields:mt("temporary_fields"),...Vs,...vs},e=>[Ki({columns:[e.choice_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]})]);ts.table("choices_unit_variants",{unit_variant_id:st("unit_variant_id").notNull(),choice_id:st("choice_id").notNull(),...zs,...Cs,position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"choices_unit_var_pk",columns:[e.unit_variant_id,e.choice_id,e._unit_variant_state,e._choice_state]}),m({name:"choices_unit_var_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[wo.unit_variant_id,wo._state]}),m({name:"choices_unit_var_choice_fk",columns:[e.choice_id,e._choice_state],foreignColumns:[So.choice_id,So._state]}),Is({name:"choices_unit_var_state_coherence",columnA:e._unit_variant_state,columnB:e._choice_state})]);const xo=ts.table("programmes",{programme_id:st("programme_id").notNull().generatedByDefaultAsIdentity(),...Es,exam_board_id:st("exam_board_id"),pathway_id:st("pathway_id"),subject_id:st("subject_id").notNull(),tier_id:st("tier_id"),year_id:st("year_id").notNull(),deprecated_fields:mt("deprecated_fields"),legacy:ze("legacy").notNull().default(!1),national_curriculum_content:ze("national_curriculum_content").notNull().default(!1),programme_uid:Le("programme_uid",{length:16}),...Vs,...vs},e=>[Ki({columns:[e.programme_id,e._state]}),m({columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]}),m({columns:[e.tier_id],foreignColumns:[vo.tier_id]}),m({name:"programmes_exam_board_fk",columns:[e.exam_board_id],foreignColumns:[yo.exam_board_id]}),m({columns:[e.pathway_id],foreignColumns:[bo.pathway_id]}),p("programmes_factor_scope_unique").on(e.subject_id,e.year_id,e.tier_id,e.exam_board_id,e.pathway_id,e.legacy,e._state).nullsNotDistinct()]);ts.table("inclusions",{programme_id:st("programme_id").notNull(),position:st("position").notNull(),...Ts,...Os,...Ls,choice_id:st("choice_id"),unit_variant_id:st("unit_variant_id"),...Vs,...vs},e=>[Ki({name:"inclusions_pk",columns:[e.programme_id,e.position,e._programme_state]}),ge("inclusions_xor_variant_choice",i.sql`num_nonnulls(${e.unit_variant_id}, ${e.choice_id}) = 1`),ge("inclusions_choice_state_matches",i.sql`(${e.choice_id} is null) = (${e._choice_state} is null)`),ge("inclusions_unit_variant_state_matches",i.sql`(${e.unit_variant_id} is null) = (${e._unit_variant_state} is null)`),Ei("inclusions_choice_unique").on(e.choice_id,e._choice_state).where(i.sql`${e.choice_id} is not null`),Ei("inclusions_programme_unit_variant_unique").on(e.programme_id,e.unit_variant_id,e._programme_state,e._unit_variant_state).where(i.sql`${e.unit_variant_id} is not null`),m({name:"inclusions_programme_fk",columns:[e.programme_id,e._programme_state],foreignColumns:[xo.programme_id,xo._state]}),m({name:"inclusions_choice_fk",columns:[e.choice_id,e._choice_state],foreignColumns:[So.choice_id,So._state]}),m({name:"inclusions_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[wo.unit_variant_id,wo._state]}),Fs({name:"inclusions_choice_state_coherence",columnA:e._programme_state,columnB:e._choice_state}),Fs({name:"inclusions_unit_var_state_coherence",columnA:e._programme_state,columnB:e._unit_variant_state})]);const Co=ts.table("subject_phases",{subject_id:st("subject_id").notNull(),phase_id:st("phase_id").notNull(),...Es,curriculum_intent:si("curriculum_intent"),deprecated_fields:mt("deprecated_fields"),prior_knowledge_requirements:ze("prior_knowledge_requirements").notNull().default(!1),related_units:ze("related_units").notNull().default(!1),unit_description:ze("unit_description").notNull().default(!1),...Vs,...vs},e=>[Ki({columns:[e.subject_id,e.phase_id,e._state]}),m({columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({columns:[e.phase_id],foreignColumns:[uo.phase_id]})]),qo=ts.table("threads",{thread_id:st("thread_id").notNull().generatedByDefaultAsIdentity(),...Ss,deprecated_fields:mt("deprecated_fields"),description:si("description"),slug:si("slug"),thread_uid:Le("thread_uid",{length:16}),title:si("title"),...Vs,...vs},e=>[Ki({columns:[e.thread_id,e._state]})]);ts.table("subject_phase_threads",{subject_id:st("subject_id").notNull(),phase_id:st("phase_id").notNull(),thread_id:st("thread_id").notNull(),...As,...Ps,deprecated_fields:mt("deprecated_fields"),position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"subject_phase_threads_pk",columns:[e.subject_id,e.phase_id,e.thread_id,e._subject_phase_state,e._thread_state]}),m({name:"subject_phase_threads_subject_phase_fk",columns:[e.subject_id,e.phase_id,e._subject_phase_state],foreignColumns:[Co.subject_id,Co.phase_id,Co._state]}),m({name:"subject_phase_threads_thread_fk",columns:[e.thread_id,e._thread_state],foreignColumns:[qo.thread_id,qo._state]}),Is({name:"subject_phase_threads_state_coherence",columnA:e._subject_phase_state,columnB:e._thread_state})]),ts.table("unit_threads",{thread_id:st("thread_id").notNull(),unit_id:st("unit_id").notNull(),...Ps,...Bs,deprecated_fields:mt("deprecated_fields"),position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"unit_threads_pk",columns:[e.thread_id,e.unit_id,e._thread_state,e._unit_state]}),m({name:"unit_threads_thread_fk",columns:[e.thread_id,e._thread_state],foreignColumns:[qo.thread_id,qo._state]}),m({name:"unit_threads_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zs.unit_id,Zs._state]}),Is({name:"unit_threads_state_coherence",columnA:e._thread_state,columnB:e._unit_state})]),ts.table("unit_catalogue",{subject_id:st("subject_id").notNull(),year_id:st("year_id").notNull(),unit_id:st("unit_id").notNull(),...Es,...Vs,...vs},e=>[Ki({columns:[e.subject_id,e.year_id,e.unit_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),m({columns:[e.subject_id],foreignColumns:[co.subject_id]}),m({columns:[e.year_id],foreignColumns:[mo.year_id]})]),ts.table("unit_lessons",{unit_id:st("unit_id").notNull(),lesson_id:st("lesson_id").notNull(),...Bs,...qs,position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"unit_lessons_pk",columns:[e.unit_id,e.lesson_id,e._unit_state,e._lesson_state]}),m({name:"unit_lessons_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zs.unit_id,Zs._state]}),m({name:"unit_lessons_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Us.lesson_id,Us._state]}),Is({name:"unit_lessons_state_coherence",columnA:e._unit_state,columnB:e._lesson_state})]),ts.table("unit_variant_lessons",{unit_variant_id:st("unit_variant_id").notNull(),lesson_id:st("lesson_id").notNull(),...zs,...qs,deprecated_fields:mt("deprecated_fields"),position:st("position").notNull(),...Vs,...vs},e=>[Ki({name:"unit_var_lessons_pk",columns:[e.unit_variant_id,e.lesson_id,e._unit_variant_state,e._lesson_state]}),m({name:"unit_var_lessons_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[wo.unit_variant_id,wo._state]}),m({name:"unit_var_lessons_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Us.lesson_id,Us._state]}),Is({name:"unit_var_lessons_state_coherence",columnA:e._unit_variant_state,columnB:e._lesson_state})]),ts.table("unit_features",{unit_id:st("unit_id").notNull(),feature_id:st("feature_id").notNull(),...Es,value:si("value"),...Vs,...vs},e=>[Ki({columns:[e.unit_id,e.feature_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zs.unit_id,Zs._state]}),m({columns:[e.feature_id],foreignColumns:[ao.feature_id]})]);const To=ns.enum("lesson_component_operation_status_enum",["api_neutral","api_in_progress","api_failed","ingest_queued","ingest_in_progress","ingest_failed","ingest_completed"]),jo=ns.enum("lesson_component_status_retirement_enum",["superseded","draft_discarded","component_expired","component_removed","orphaned"]);ns.table("lesson_component_status",{lesson_component_status_id:gi("lesson_component_status_id").primaryKey().defaultRandom(),lesson_component_id:st("lesson_component_id").notNull(),lesson_component_type:bs("lesson_component_type").notNull(),active_media_id:st("active_media_id"),active_media_type:ys("active_media_type"),last_error_location:si("last_error_location"),last_error_message:si("last_error_message"),last_error_timestamp:ci("last_error_timestamp"),last_ingest_id:gi("last_ingest_id"),operation_status:To("operation_status").notNull().default("api_neutral"),previous_media_id:st("previous_media_id"),previous_media_type:ys("previous_media_type"),retired_at:ci("retired_at",{withTimezone:!0}),retired_reason:jo("retired_reason"),...vs},e=>[ge("lesson_comp_status_retired_both",i.sql`(${e.retired_at} is null) = (${e.retired_reason} is null)`),Ei("lesson_comp_status_live_unq").on(e.lesson_component_id,e.lesson_component_type).where(i.sql`${e.retired_at} is null`)]);const $o=ns.enum("lesson_status_enum",["api_neutral","ingest_queued","ingest_in_progress","ingest_complete","ingest_failed"]);ns.table("lesson_status",{lesson_id:st("lesson_id").primaryKey(),approved:ze("approved").notNull().default(!1),last_approved:ci("last_approved"),last_error_location:si("last_error_location"),last_error_message:si("last_error_message"),last_error_timestamp:ci("last_error_timestamp"),status:$o("status").notNull().default("api_neutral"),...vs});const Ao=ns.enum("media_status_enum",["neutral","in_progress","failed"]),Po=ns.enum("media_status_retirement_enum",["superseded","media_retired","orphaned"]);ns.table("media_status",{media_status_id:gi("media_status_id").primaryKey().defaultRandom(),media_id:st("media_id").notNull(),media_type:ys("media_type").notNull(),last_error_location:si("last_error_location"),last_error_message:si("last_error_message"),last_error_timestamp:ci("last_error_timestamp"),last_lesson_component_id:st("last_lesson_component_id"),last_lesson_component_type:bs("last_lesson_component_type"),retired_at:ci("retired_at",{withTimezone:!0}),retired_reason:Po("retired_reason"),status:Ao("status").notNull().default("neutral"),...vs},e=>[ge("media_status_retired_both",i.sql`(${e.retired_at} is null) = (${e.retired_reason} is null)`),Ei("media_status_live_unq").on(e.media_id,e.media_type).where(i.sql`${e.retired_at} is null`)]),ns.table("mutations_log",{mutations_log_id:gi("mutations_log_id").primaryKey().defaultRandom(),actor_role:si("actor_role"),actor_type:si("actor_type"),app_id:si("app_id"),changes:mt("changes").notNull(),operation:fs("operation").notNull(),record_key:mt("record_key").notNull(),table_name:si("table_name").notNull(),...ws},e=>[Vi("idx_mutations_log_record_key").using("gin",e.record_key)]),ns.table("release_snapshots",{release_snapshot_id:gi("release_snapshot_id").primaryKey().defaultRandom(),_release_id:st("_release_id"),source_created_at:ci("source_created_at"),source_id:st("source_id"),source_row:mt("source_row"),source_schema:si("source_schema").default(""),source_state:ss("source_state").notNull(),source_table:si("source_table").default(""),source_uid:Le("source_uid",{length:16}),source_updated_at:ci("source_updated_at")},e=>[m({columns:[e._release_id],foreignColumns:[ks.release_id]}),Vi("release_snapshots_source_idx").on(e.source_schema,e.source_table,e.source_id),Vi("release_snapshots_release_idx").on(e._release_id)]);const Bo=ns.enum("contract_log_event_type_enum",["works_change","contract_change","works_added_to_contract"]);ns.table("tpc_contract_log",{tpc_contract_log_id:st("tpc_contract_log_id").primaryKey().generatedByDefaultAsIdentity(),tpc_contract_id:st("tpc_contract_id").notNull(),changed_at:ci("changed_at",{withTimezone:!0}).notNull(),event_type:Bo("event_type").notNull(),payload:mt("payload")},e=>[m({name:"tpc_contract_log_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[so.tpc_contract_id]})]);const zo=ns.enum("restrictions_type_enum",["Restrictions 1","Restrictions 2","Restrictions 3","Restrictions 4","Restrictions 5","Restrictions 6","Restrictions 7","Additional Restrictions"]),Do=ns.table("tpc_restriction_definitions",{tpc_restriction_definition_id:st("tpc_restriction_definition_id").primaryKey().generatedByDefaultAsIdentity(),restriction_text:si("restriction_text").notNull(),type:zo("type").notNull(),...vs},e=>[p("tpc_restriction_definitions_type_unique").on(e.type,e.restriction_text)]);ns.table("tpc_restrictions",{tpc_contract_id:st("tpc_contract_id").notNull(),tpc_restriction_definition_id:st("tpc_restriction_definition_id").notNull(),...Es,restriction_override:si("restriction_override"),...vs},e=>[Ki({name:"tpc_restrictions_pk",columns:[e.tpc_contract_id,e.tpc_restriction_definition_id,e._state]}),m({name:"tpc_restrictions_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[so.tpc_contract_id]}),m({name:"tpc_restrictions_tpc_restriction_definition_fk",columns:[e.tpc_restriction_definition_id],foreignColumns:[Do.tpc_restriction_definition_id]})]),is.view("sub_published_documents_with_release_by_lesson",{document_id:st("document_id").notNull(),document_type:Js("document_type").notNull(),document_uid:Le("document_uid",{length:16}),lesson_id:st("lesson_id"),previous_lesson_id:st("previous_lesson_id"),gdrive_file_id:st("gdrive_file_id").notNull(),epoch:si("epoch"),google_drive_id:si("google_drive_id"),google_drive_url:si("google_drive_url"),opendocument_presentation_bucket_name:si("opendocument_presentation_bucket_name"),opendocument_presentation_bucket_path:si("opendocument_presentation_bucket_path"),opendocument_text_bucket_name:si("opendocument_text_bucket_name"),opendocument_text_bucket_path:si("opendocument_text_bucket_path"),pdf_bucket_name:si("pdf_bucket_name"),pdf_bucket_path:si("pdf_bucket_path"),powerpoint_bucket_name:si("powerpoint_bucket_name"),powerpoint_bucket_path:si("powerpoint_bucket_path"),word_bucket_name:si("word_bucket_name"),word_bucket_path:si("word_bucket_path"),release_id:st("release_id"),r_approved:ze("r_approved"),r_description:si("r_description"),r_estimated_release_date:He("r_estimated_release_date"),r_name:si("r_name"),r_notes:si("r_notes"),r_release_type:Ns("r_release_type"),_expire_on_release:ze("_expire_on_release").notNull(),_release_id:st("_release_id"),created_at:ci("created_at",{withTimezone:!0}),updated_at:ci("updated_at",{withTimezone:!0}),r_created_at:ci("r_created_at",{withTimezone:!0}),r_updated_at:ci("r_updated_at",{withTimezone:!0})}).as(i.sql`
|
|
7
|
+
`;await i.execute(te`CREATE SCHEMA IF NOT EXISTS ${te.identifier(n)}`),await i.execute(_);const a=(await i.all(te`select id, hash, created_at from ${te.identifier(n)}.${te.identifier(s)} order by created_at desc limit 1`))[0];await i.transaction(async i=>{for await(const t of e)if(!a||Number(a.created_at)<t.folderMillis){for(const e of t.sql)await i.execute(te.raw(e));await i.execute(te`insert into ${te.identifier(n)}.${te.identifier(s)} ("hash", "created_at") values(${t.hash}, ${t.folderMillis})`)}})}escapeName(e){return`"${e.replace(/"/g,'""')}"`}escapeParam(e){return`$${e+1}`}escapeString(e){return`'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;const i=[te`with `];for(const[t,s]of e.entries())i.push(te`${te.identifier(s._.alias)} as (${s._.sql})`),t<e.length-1&&i.push(te`, `);return i.push(te` `),te.join(i)}buildDeleteQuery({table:e,where:i,returning:t,withList:s}){return te`${this.buildWithCTE(s)}delete from ${e}${i?te` where ${i}`:void 0}${t?te` returning ${this.buildSelection(t,{isSingleTable:!0})}`:void 0}`}buildUpdateSet(e,i){const t=e[R.Symbol.Columns],s=Object.keys(t).filter(e=>void 0!==i[e]||void 0!==t[e]?.onUpdateFn),n=s.length;return te.join(s.flatMap((e,s)=>{const _=t[e],a=_.onUpdateFn?.(),r=i[e]??(o(a,Y)?a:te.param(a,_)),l=te`${te.identifier(this.casing.getColumnCasing(_))} = ${r}`;return s<n-1?[l,te.raw(", ")]:[l]}))}buildUpdateQuery({table:e,set:i,where:t,returning:s,withList:n,from:_,joins:a}){const o=this.buildWithCTE(n),r=e[Dt.Symbol.Name],l=e[Dt.Symbol.Schema],d=e[Dt.Symbol.OriginalName],u=r===d?void 0:r,c=te`${l?te`${te.identifier(l)}.`:void 0}${te.identifier(d)}${u&&te` ${te.identifier(u)}`}`,m=this.buildUpdateSet(e,i),p=_&&te.join([te.raw(" from "),this.buildFromTable(_)]);return te`${o}update ${c} set ${m}${p}${this.buildJoins(a)}${t?te` where ${t}`:void 0}${s?te` returning ${this.buildSelection(s,{isSingleTable:!_})}`:void 0}`}buildSelection(e,{isSingleTable:i=!1}={}){const t=e.length,s=e.flatMap(({field:e},s)=>{const n=[];if(o(e,Y.Aliased)&&e.isSelectionField)n.push(te.identifier(e.fieldAlias));else if(o(e,Y.Aliased)||o(e,Y)){const t=o(e,Y.Aliased)?e.sql:e;i?n.push(new Y(t.queryChunks.map(e=>o(e,S)?te.identifier(this.casing.getColumnCasing(e)):e))):n.push(t),o(e,Y.Aliased)&&n.push(te` as ${te.identifier(e.fieldAlias)}`)}else if(o(e,r))i?n.push(te.identifier(this.casing.getColumnCasing(e))):n.push(e);else if(o(e,B)){const i=Object.entries(e._.selectedFields);if(1===i.length){const t=i[0][1],s=o(t,Y)?t.decoder:o(t,r)?{mapFromDriverValue:e=>t.mapFromDriverValue(e)}:t.sql.decoder;s&&(e._.sql.decoder=s)}n.push(e)}return s<t-1&&n.push(te`, `),n});return te.join(s)}buildJoins(e){if(!e||0===e.length)return;const i=[];for(const[t,s]of e.entries()){0===t&&i.push(te` `);const n=s.table,_=s.lateral?te` lateral`:void 0,a=s.on?te` on ${s.on}`:void 0;if(o(n,Dt)){const e=n[Dt.Symbol.Name],t=n[Dt.Symbol.Schema],o=n[Dt.Symbol.OriginalName],r=e===o?void 0:s.alias;i.push(te`${te.raw(s.joinType)} join${_} ${t?te`${te.identifier(t)}.`:void 0}${te.identifier(o)}${r&&te` ${te.identifier(r)}`}${a}`)}else if(o(n,ae)){const e=n[L].name,t=n[L].schema,o=n[L].originalName,r=e===o?void 0:s.alias;i.push(te`${te.raw(s.joinType)} join${_} ${t?te`${te.identifier(t)}.`:void 0}${te.identifier(o)}${r&&te` ${te.identifier(r)}`}${a}`)}else i.push(te`${te.raw(s.joinType)} join${_} ${n}${a}`);t<e.length-1&&i.push(te` `)}return te.join(i)}buildFromTable(e){if(o(e,R)&&e[R.Symbol.IsAlias]){let i=te`${te.identifier(e[R.Symbol.OriginalName])}`;return e[R.Symbol.Schema]&&(i=te`${te.identifier(e[R.Symbol.Schema])}.${i}`),te`${i} ${te.identifier(e[R.Symbol.Name])}`}return e}buildSelectQuery({withList:e,fields:i,fieldsFlat:t,where:s,having:n,table:_,joins:a,orderBy:l,groupBy:d,limit:u,offset:c,lockingClause:m,distinct:p,setOperators:g}){const f=t??fe(i);for(const e of f)if(o(e.field,r)&&M(e.field.table)!==(o(_,B)?_._.alias:o(_,As)?_[L].name:o(_,Y)?void 0:M(_))&&!(e=>a?.some(({alias:i})=>i===(e[R.Symbol.IsAlias]?M(e):e[R.Symbol.BaseName])))(e.field.table)){const i=M(e.field.table);throw new Error(`Your "${e.path.join("->")}" field references a column "${i}"."${e.field.name}", but the table "${i}" is not part of the query! Did you forget to join it?`)}const h=!a||0===a.length,v=this.buildWithCTE(e);let y;p&&(y=!0===p?te` distinct`:te` distinct on (${te.join(p.on,te`, `)})`);const b=this.buildSelection(f,{isSingleTable:h}),w=this.buildFromTable(_),N=this.buildJoins(a),k=s?te` where ${s}`:void 0,S=n?te` having ${n}`:void 0;let x,A;l&&l.length>0&&(x=te` order by ${te.join(l,te`, `)}`),d&&d.length>0&&(A=te` group by ${te.join(d,te`, `)}`);const C="object"==typeof u||"number"==typeof u&&u>=0?te` limit ${u}`:void 0,q=c?te` offset ${c}`:void 0,T=te.empty();if(m){const e=te` for ${te.raw(m.strength)}`;m.config.of&&e.append(te` of ${te.join(Array.isArray(m.config.of)?m.config.of:[m.config.of],te`, `)}`),m.config.noWait?e.append(te` nowait`):m.config.skipLocked&&e.append(te` skip locked`),T.append(e)}const j=te`${v}select${y} ${b} from ${w}${N}${k}${A}${S}${x}${C}${q}${T}`;return g.length>0?this.buildSetOperations(j,g):j}buildSetOperations(e,i){const[t,...s]=i;if(!t)throw new Error("Cannot pass undefined values to any set operator");return 0===s.length?this.buildSetOperationQuery({leftSelect:e,setOperator:t}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:t}),s)}buildSetOperationQuery({leftSelect:e,setOperator:{type:i,isAll:t,rightSelect:s,limit:n,orderBy:_,offset:a}}){const r=te`(${e.getSQL()}) `,l=te`(${s.getSQL()})`;let d;if(_&&_.length>0){const e=[];for(const i of _)if(o(i,S))e.push(te.identifier(i.name));else if(o(i,Y)){for(let e=0;e<i.queryChunks.length;e++){const t=i.queryChunks[e];o(t,S)&&(i.queryChunks[e]=te.identifier(t.name))}e.push(te`${i}`)}else e.push(te`${i}`);d=te` order by ${te.join(e,te`, `)} `}const u="object"==typeof n||"number"==typeof n&&n>=0?te` limit ${n}`:void 0,c=te.raw(`${i} ${t?"all ":""}`);return te`${r}${c}${l}${d}${u}${a?te` offset ${a}`:void 0}`}buildInsertQuery({table:e,values:i,onConflict:t,returning:s,withList:n,select:_,overridingSystemValue_:a}){const r=[],l=e[R.Symbol.Columns],d=Object.entries(l).filter(([e,i])=>!i.shouldDisableInsert()),u=d.map(([,e])=>te.identifier(this.casing.getColumnCasing(e)));if(_){const e=i;o(e,Y)?r.push(e):r.push(e.getSQL())}else{const e=i;r.push(te.raw("values "));for(const[i,t]of e.entries()){const s=[];for(const[e,i]of d){const n=t[e];if(void 0===n||o(n,ie)&&void 0===n.value)if(void 0!==i.defaultFn){const e=i.defaultFn(),t=o(e,Y)?e:te.param(e,i);s.push(t)}else if(i.default||void 0===i.onUpdateFn)s.push(te`default`);else{const e=i.onUpdateFn(),t=o(e,Y)?e:te.param(e,i);s.push(t)}else s.push(n)}r.push(s),i<e.length-1&&r.push(te`, `)}}const c=this.buildWithCTE(n),m=te.join(r);return te`${c}insert into ${e} ${u} ${!0===a?te`overriding system value `:void 0}${m}${t?te` on conflict ${t}`:void 0}${s?te` returning ${this.buildSelection(s,{isSingleTable:!0})}`:void 0}`}buildRefreshMaterializedViewQuery({view:e,concurrently:i,withNoData:t}){return te`refresh materialized view${i?te` concurrently`:void 0} ${e}${t?te` with no data`:void 0}`}prepareTyping(e){return o(e,ci)||o(e,li)?"json":o(e,Ai)?"decimal":o(e,at)?"time":o(e,lt)||o(e,ut)?"timestamp":o(e,Re)||o(e,We)?"date":o(e,pt)?"uuid":"none"}sqlToQuery(e,i){return e.toQuery({casing:this.casing,escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,prepareTyping:this.prepareTyping,invokeSource:i})}buildRelationalQueryWithoutPK({fullSchema:e,schema:i,tableNamesMap:t,table:s,tableConfig:n,queryConfig:_,tableAlias:a,nestedQueryRelation:l,joinOn:d}){let u,c,m,p=[],g=[];const f=[];if(!0===_){p=Object.entries(n.columns).map(([e,i])=>({dbKey:i.name,tsKey:e,field:de(i,a),relationTableTsKey:void 0,isJson:!1,selection:[]}))}else{const s=Object.fromEntries(Object.entries(n.columns).map(([e,i])=>[e,de(i,a)]));if(_.where){const e="function"==typeof _.where?_.where(s,{and:is,between:ps,eq:Xt,exists:cs,gt:ns,gte:_s,ilike:vs,inArray:rs,isNull:ds,isNotNull:us,like:fs,lt:as,lte:os,ne:es,not:ss,notBetween:gs,notExists:ms,notLike:hs,notIlike:ys,notInArray:ls,or:ts,sql:te}):_.where;m=e&&ce(e,a)}const l=[];let d=[];if(_.columns){let e=!1;for(const[i,t]of Object.entries(_.columns))void 0!==t&&i in n.columns&&(e||!0!==t||(e=!0),d.push(i));d.length>0&&(d=e?d.filter(e=>!0===_.columns?.[e]):Object.keys(n.columns).filter(e=>!d.includes(e)))}else d=Object.keys(n.columns);for(const e of d){const i=n.columns[e];l.push({tsKey:e,value:i})}let h,v=[];if(_.with&&(v=Object.entries(_.with).filter(e=>!!e[1]).map(([e,i])=>({tsKey:e,queryConfig:i,relation:n.relations[e]}))),_.extras){h="function"==typeof _.extras?_.extras(s,{sql:te}):_.extras;for(const[e,i]of Object.entries(h))l.push({tsKey:e,value:ue(i,a)})}for(const{tsKey:e,value:i}of l)p.push({dbKey:o(i,Y.Aliased)?i.fieldAlias:n.columns[e].name,tsKey:e,field:o(i,r)?de(i,a):i,relationTableTsKey:void 0,isJson:!1,selection:[]});let y="function"==typeof _.orderBy?_.orderBy(s,{sql:te,asc:bs,desc:ws}):_.orderBy??[];Array.isArray(y)||(y=[y]),g=y.map(e=>o(e,r)?de(e,a):ce(e,a)),u=_.limit,c=_.offset;for(const{tsKey:s,queryConfig:n,relation:_}of v){const r=xs(i,t,_),l=t[W(_.referencedTable)],d=`${a}_${s}`,u=is(...r.fields.map((e,i)=>Xt(de(r.references[i],d),de(e,a)))),c=this.buildRelationalQueryWithoutPK({fullSchema:e,schema:i,tableNamesMap:t,table:e[l],tableConfig:i[l],queryConfig:o(_,ks)?!0===n?{limit:1}:{...n,limit:1}:n,tableAlias:d,joinOn:u,nestedQueryRelation:_}),m=te`${te.identifier(d)}.${te.identifier("data")}`.as(s);f.push({on:te`true`,table:new B(c.sql,{},d),alias:d,joinType:"left",lateral:!0}),p.push({dbKey:s,tsKey:s,field:m,relationTableTsKey:l,isJson:!0,selection:c.selection})}}if(0===p.length)throw new Yt({message:`No fields selected for table "${n.tsName}" ("${a}")`});let h;if(m=is(d,m),l){let e=te`json_build_array(${te.join(p.map(({field:e,tsKey:i,isJson:t})=>t?te`${te.identifier(`${a}_${i}`)}.${te.identifier("data")}`:o(e,Y.Aliased)?e.sql:e),te`, `)})`;o(l,Ss)&&(e=te`coalesce(json_agg(${e}${g.length>0?te` order by ${te.join(g,te`, `)}`:void 0}), '[]'::json)`);const i=[{dbKey:"data",tsKey:"data",field:e.as("data"),isJson:!0,relationTableTsKey:n.tsName,selection:p}];void 0!==u||void 0!==c||g.length>0?(h=this.buildSelectQuery({table:le(s,a),fields:{},fieldsFlat:[{path:[],field:te.raw("*")}],where:m,limit:u,offset:c,orderBy:g,setOperators:[]}),m=void 0,u=void 0,c=void 0,g=[]):h=le(s,a),h=this.buildSelectQuery({table:o(h,Dt)?h:new B(h,{},a),fields:{},fieldsFlat:i.map(({field:e})=>({path:[],field:o(e,r)?de(e,a):e})),joins:f,where:m,limit:u,offset:c,orderBy:g,setOperators:[]})}else h=this.buildSelectQuery({table:le(s,a),fields:{},fieldsFlat:p.map(({field:e})=>({path:[],field:o(e,r)?de(e,a):e})),joins:f,where:m,limit:u,offset:c,orderBy:g,setOperators:[]});return{tableTsKey:n.tsName,sql:h,selection:p}}}class qs{static[a]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class Ts{static[a]="PgSelectBuilder";fields;session;dialect;withList=[];distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,e.withList&&(this.withList=e.withList),this.distinct=e.distinct}authToken;setToken(e){return this.authToken=e,this}from(e){const i=!!this.fields,t=e;let s;return s=this.fields?this.fields:o(t,B)?Object.fromEntries(Object.keys(t._.selectedFields).map(e=>[e,t[e]])):o(t,As)?t[L].selectedFields:o(t,Y)?{}:ve(t),new $s({table:t,fields:s,isPartialSelect:i,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct}).setToken(this.authToken)}}class js extends qs{static[a]="PgSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:i,isPartialSelect:t,session:s,dialect:n,withList:_,distinct:a}){super(),this.config={withList:_,table:e,fields:{...i},distinct:a,setOperators:[]},this.isPartialSelect=t,this.session=s,this.dialect=n,this._={selectedFields:i,config:this.config},this.tableName=ye(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{};for(const i of Gs(e))this.usedTables.add(i)}getUsedTables(){return[...this.usedTables]}createJoin(e,i){return(t,s)=>{const n=this.tableName,_=ye(t);for(const e of Gs(t))this.usedTables.add(e);if("string"==typeof _&&this.config.joins?.some(e=>e.alias===_))throw new Error(`Alias "${_}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof n&&(this.config.fields={[n]:this.config.fields}),"string"==typeof _&&!o(t,Y))){const e=o(t,B)?t._.selectedFields:o(t,ae)?t[L].selectedFields:t[R.Symbol.Columns];this.config.fields[_]=e}if("function"==typeof s&&(s=s(new Proxy(this.config.fields,new Pt({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:s,table:t,joinType:e,alias:_,lateral:i}),"string"==typeof _)switch(e){case"left":this.joinsNotNullableMap[_]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[_]=!0;break;case"cross":case"inner":this.joinsNotNullableMap[_]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[_]=!1}return this}}leftJoin=this.createJoin("left",!1);leftJoinLateral=this.createJoin("left",!0);rightJoin=this.createJoin("right",!1);innerJoin=this.createJoin("inner",!1);innerJoinLateral=this.createJoin("inner",!0);fullJoin=this.createJoin("full",!1);crossJoin=this.createJoin("cross",!1);crossJoinLateral=this.createJoin("cross",!0);createSetOperator(e,i){return t=>{const s="function"==typeof t?t(zs()):t;if(!he(this.getSelectedFields(),s.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:i,rightSelect:s}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);intersectAll=this.createSetOperator("intersect",!0);except=this.createSetOperator("except",!1);exceptAll=this.createSetOperator("except",!0);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new Pt({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new Pt({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){const i=e[0](new Proxy(this.config.fields,new Pt({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(i)?i:[i]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){const i=e[0](new Proxy(this.config.fields,new Pt({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),t=Array.isArray(i)?i:[i];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=t:this.config.orderBy=t}else{const i=e;this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}for(e,i={}){return this.config.lockingClause={strength:e,config:i},this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){const{typings:e,...i}=this.dialect.sqlToQuery(this.getSQL());return i}as(e){const i=[];if(i.push(...Gs(this.config.table)),this.config.joins)for(const e of this.config.joins)i.push(...Gs(e.table));return new Proxy(new B(this.getSQL(),this.config.fields,e,!1,[...new Set(i)]),new Pt({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new Pt({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}$withCache(e){return this.cacheConfig=void 0===e?{config:{},enable:!0,autoInvalidate:!0}:!1===e?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}}class $s extends js{static[a]="PgSelect";_prepare(e){const{session:i,config:t,dialect:s,joinsNotNullableMap:n,authToken:_,cacheConfig:a,usedTables:o}=this;if(!i)throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");const{fields:r}=t;return O.startActiveSpan("drizzle.prepareQuery",()=>{const t=fe(r),l=i.prepareQuery(s.sqlToQuery(this.getSQL()),t,e,!0,void 0,{type:"select",tables:[...o]},a);return l.joinsNotNullableMap=n,l.setToken(_)})}prepare(e){return this._prepare(e)}authToken;setToken(e){return this.authToken=e,this}execute=e=>O.startActiveSpan("drizzle.operation",()=>this._prepare().execute(e,this.authToken))}function Ps(e,i){return(t,s,...n)=>{const _=[s,...n].map(t=>({type:e,isAll:i,rightSelect:t}));for(const e of _)if(!he(t.getSelectedFields(),e.rightSelect.getSelectedFields()))throw new Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return t.addSetOperators(_)}}!function(e,i){for(const t of i)for(const i of Object.getOwnPropertyNames(t.prototype))"constructor"!==i&&Object.defineProperty(e.prototype,i,Object.getOwnPropertyDescriptor(t.prototype,i)||Object.create(null))}($s,[$t]);const zs=()=>({union:Bs,unionAll:Ds,intersect:Os,intersectAll:Ls,except:Is,exceptAll:Fs}),Bs=Ps("union",!1),Ds=Ps("union",!0),Os=Ps("intersect",!1),Ls=Ps("intersect",!0),Is=Ps("except",!1),Fs=Ps("except",!0);class Qs{static[a]="PgQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=o(e,Cs)?e:void 0,this.dialectConfig=o(e,Cs)?void 0:e}$with=(e,i)=>{const t=this;return{as:s=>("function"==typeof s&&(s=s(t)),new Proxy(new D(s.getSQL(),i??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new Pt({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){const i=this;return{select:function(t){return new Ts({fields:t??void 0,session:void 0,dialect:i.getDialect(),withList:e})},selectDistinct:function(e){return new Ts({fields:e??void 0,session:void 0,dialect:i.getDialect(),distinct:!0})},selectDistinctOn:function(e,t){return new Ts({fields:t??void 0,session:void 0,dialect:i.getDialect(),distinct:{on:e}})}}}select(e){return new Ts({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new Ts({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}selectDistinctOn(e,i){return new Ts({fields:i??void 0,session:void 0,dialect:this.getDialect(),distinct:{on:e}})}getDialect(){return this.dialect||(this.dialect=new Cs(this.dialectConfig)),this.dialect}}class Es{constructor(e,i){this.name=e,this.schema=i}static[a]="PgDefaultViewBuilderCore";config={};with(e){return this.config.with=e,this}}class Vs extends Es{static[a]="PgViewBuilder";as(e){"function"==typeof e&&(e=e(new Qs));const i=new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}),t=new Proxy(e.getSelectedFields(),i);return new Proxy(new Ms({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:t,query:e.getSQL().inlineParams()}}),i)}}class Ks extends Es{static[a]="PgManualViewBuilder";columns;constructor(e,i,t){super(e,t),this.columns=ve(Lt(e,i))}existing(){return new Proxy(new Ms({pgConfig:void 0,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}as(e){return new Proxy(new Ms({pgConfig:this.config,config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}}class Us{constructor(e,i){this.name=e,this.schema=i}static[a]="PgMaterializedViewBuilderCore";config={};using(e){return this.config.using=e,this}with(e){return this.config.with=e,this}tablespace(e){return this.config.tablespace=e,this}withNoData(){return this.config.withNoData=!0,this}}class Js extends Us{static[a]="PgMaterializedViewBuilder";as(e){"function"==typeof e&&(e=e(new Qs));const i=new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}),t=new Proxy(e.getSelectedFields(),i);return new Proxy(new Hs({pgConfig:{with:this.config.with,using:this.config.using,tablespace:this.config.tablespace,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:t,query:e.getSQL().inlineParams()}}),i)}}class Rs extends Us{static[a]="PgManualMaterializedViewBuilder";columns;constructor(e,i,t){super(e,t),this.columns=ve(Lt(e,i))}existing(){return new Proxy(new Hs({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:void 0}}),new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}as(e){return new Proxy(new Hs({pgConfig:{tablespace:this.config.tablespace,using:this.config.using,with:this.config.with,withNoData:this.config.withNoData},config:{name:this.name,schema:this.schema,selectedFields:this.columns,query:e.inlineParams()}}),new Pt({alias:this.name,sqlBehavior:"error",sqlAliasedBehavior:"alias",replaceOriginalName:!0}))}}class Ms extends As{static[a]="PgView";[Rt];constructor({pgConfig:e,config:i}){super(i),e&&(this[Rt]={with:e.with})}}const Ws=Symbol.for("drizzle:PgMaterializedViewConfig");class Hs extends As{static[a]="PgMaterializedView";[Ws];constructor({pgConfig:e,config:i}){super(i),this[Ws]={with:e?.with,using:e?.using,tablespace:e?.tablespace,withNoData:e?.withNoData}}}function Gs(e){return o(e,Dt)?[e[I]?`${e[I]}.${e[R.Symbol.BaseName]}`:e[R.Symbol.BaseName]]:o(e,B)?e._.usedTables??[]:o(e,Y)?e.usedTables??[]:[]}class Ys{constructor(e,i,t){this.seqName=e,this.seqOptions=i,this.schema=t}static[a]="PgSequence"}class Zs{constructor(e){this.schemaName=e}static[a]="PgSchema";table=(e,i,t)=>Ot(e,i,t,this.schemaName);view=(e,i)=>function(e,i,t){return i?new Ks(e,i,t):new Vs(e,t)}(e,i,this.schemaName);materializedView=(e,i)=>function(e,i,t){return i?new Rs(e,i,t):new Js(e,t)}(e,i,this.schemaName);enum(e,i){return Array.isArray(i)?function(e,i,t){const s=Object.assign(e=>new P(e??"",s),{enumName:e,enumValues:i,schema:t,[$]:!0});return s}(e,[...i],this.schemaName):function(e,i,t){const s=Object.assign(e=>new T(e??"",s),{enumName:e,enumValues:Object.values(i),schema:t,[$]:!0});return s}(e,i,this.schemaName)}sequence=(e,i)=>function(e,i,t){return new Ys(e,i,t)}(e,i,this.schemaName);getSQL(){return new Y([te.identifier(this.schemaName)])}shouldOmitSQLParens(){return!0}}function Xs(e){if("public"===e)throw new Error("You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use pgTable() instead of creating a schema");return new Zs(e)}const en=Xs("raw"),tn=Xs("rendered"),sn=Xs("internal");Xs("cached");const nn=en.enum("state",["draft","published","expired"]),_n=en.enum("restriction_level",["ogl_compatible","ogl_equivalent","restricted","highly_restricted"]),an=en.enum("media_provenance",["oak_created","oak_illustration","partner_created","creative_commons","pixabay","pexels","unsplash","openverse","freesvg","needpix","bridgeman","shutterstock","dall_e","adobe_firefly","other"]),on=en.enum("acquisition_basis",["oak_owned","public_domain","gratis","paid","creative_commons"]),rn=en.enum("permission_status",["not_required","granted","denied"]),ln=en.enum("territory",["uk","worldwide","worldwide_no_usa","other_territory"]),dn=en.enum("licence",["cc0","cc_by","cc_by_sa","cc_by_nc","cc_by_nc_sa","cc_by_nc_nd","cc_by_nd","ogl","unlimited_use","limited_use_permission_required","single_use_permission_required","other"]),un=en.enum("question_type",["explanatory-text","match","multiple-choice","order","short-answer","text"]),cn=en.enum("tag_category",["discipline","domain","world_view"]),mn=en.enum("media_kind",["video","sound"]),pn=en.enum("clip_section",["intro","lesson_outline"]),gn=en.enum("redirect_type",["301","302","307","308"]),fn=en.enum("redirect_entity_source",["lessons","units","programmes","subjects"]),hn=sn.enum("operation",["insert","update","delete"]),vn=sn.enum("media_type_enum",["video","sound","gdrive_file","bucket_file"]),yn=sn.enum("lesson_component_type_enum",["document","downloadable","lesson_video","media_clip","quiz"]),bn={created_at:ct("created_at",{withTimezone:!0}).defaultNow(),updated_at:ct("updated_at",{withTimezone:!0}).$onUpdateFn(()=>new Date)},wn={created_at:ct("created_at",{withTimezone:!0}).notNull().defaultNow()},Nn=sn.enum("release_type",["mathfix","migration"]),kn=sn.table("releases",{release_id:ni("release_id").primaryKey().generatedByDefaultAsIdentity(),_authoring_state:nn("_authoring_state").notNull(),approved:Be("approved").notNull().default(!1),approver:mi("approver"),description:nt("description"),estimated_release_date:He("estimated_release_date"),locked:Be("locked").notNull().default(!1),name:nt("name"),notes:nt("notes"),release_type:Nn("release_type"),release_uid:Le("release_uid",{length:16}),...bn}),Sn={_state:nn("_state").notNull()},xn={_authoring_state:nn("_authoring_state").notNull()},An={_choice_state:nn("_choice_state").notNull()},Cn={_lesson_state:nn("_lesson_state").notNull()},qn={_programme_state:nn("_programme_state").notNull()},Tn={_question_state:nn("_question_state").notNull()},jn={_quiz_state:nn("_quiz_state").notNull()},$n={_subject_phase_state:nn("_subject_phase_state").notNull()},Pn={_thread_state:nn("_thread_state").notNull()},zn={_unit_state:nn("_unit_state").notNull()},Bn={_unit_variant_state:nn("_unit_variant_state").notNull()},Dn={_works_copyright_state:nn("_works_copyright_state").notNull()},On={_choice_state:nn("_choice_state")},Ln={_unit_variant_state:nn("_unit_variant_state")},In=({name:e,columnA:i,columnB:s})=>ge(e,t.sql`${i} = 'expired' or ${s} = 'expired' or ${i} = ${s}`),Fn=({name:e,columnA:i,columnB:s})=>ge(e,t.sql`${i} = 'expired' or ${s} is null or ${s} = 'expired' or ${i} = ${s}`),Qn=({name:e,columnA:i,columnB:s,allow:n})=>ge(e,t.sql.join([t.sql`${i} = 'expired'`,t.sql`${s} = 'expired'`,t.sql`${i} = ${s}`,...n.map(([e,n])=>t.sql`(${i} = ${t.sql.raw(`'${e}'`)} and ${s} = ${t.sql.raw(`'${n}'`)})`)],t.sql` or `)),En={_expire_on_release:Be("_expire_on_release").notNull().default(!1),_release_id:ni("_release_id").references(()=>kn.release_id)},Vn=Sn,Kn=en.table("gdrive_files",{gdrive_file_id:ni("gdrive_file_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),epoch:nt("epoch"),google_drive_id:nt("google_drive_id"),google_drive_url:nt("google_drive_url"),opendocument_presentation_bucket_name:nt("opendocument_presentation_bucket_name"),opendocument_presentation_bucket_path:nt("opendocument_presentation_bucket_path"),opendocument_text_bucket_name:nt("opendocument_text_bucket_name"),opendocument_text_bucket_path:nt("opendocument_text_bucket_path"),pdf_bucket_name:nt("pdf_bucket_name"),pdf_bucket_path:nt("pdf_bucket_path"),powerpoint_bucket_name:nt("powerpoint_bucket_name"),powerpoint_bucket_path:nt("powerpoint_bucket_path"),previous_document_id:ni("previous_document_id"),word_bucket_name:nt("word_bucket_name"),word_bucket_path:nt("word_bucket_path"),...En,...bn}),Un=en.table("lessons",{lesson_id:ni("lesson_id").notNull().generatedByDefaultAsIdentity(),...Vn,agf__has_copyright_restrictions:Be("agf__has_copyright_restrictions"),agf__restricted_download:Be("agf__restricted_download"),deprecated_fields:mi("deprecated_fields"),equipment_and_resources:mi("equipment_and_resources"),has_tag_practical_not_remote:Be("has_tag_practical_not_remote").notNull().default(!1),is_sensitive:Be("is_sensitive").notNull().default(!1),key_learning_points:mi("key_learning_points"),keywords:mi("keywords"),lesson_outline:mi("lesson_outline"),lesson_uid:Le("lesson_uid",{length:16}).notNull(),misconceptions_and_common_mistakes:mi("misconceptions_and_common_mistakes"),phonics_outcome:nt("phonics_outcome"),pupil_lesson_outcome:nt("pupil_lesson_outcome"),slug:nt("slug").notNull(),teacher_tips:mi("teacher_tips"),title:nt("title").notNull(),...En,...bn},e=>[Kt({columns:[e.lesson_id,e._state]}),p("lessons_slug_unique").on(e.slug,e._state)]),Jn=en.enum("document_type",["slidedeck","worksheet","worksheet_answers","supplementary_resource","lesson_guide"]);en.table("documents",{document_id:ni("document_id").notNull().generatedByDefaultAsIdentity(),...Vn,gdrive_file_id:ni("gdrive_file_id").notNull(),lesson_id:ni("lesson_id"),deprecated_fields:mi("deprecated_fields"),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}),previous_lesson_id:ni("previous_lesson_id"),...En,...bn},e=>[Kt({columns:[e.document_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"documents_gdrive_file_fk",columns:[e.gdrive_file_id],foreignColumns:[Kn.gdrive_file_id]}),p().on(e.lesson_id,e.document_type,e._state)]);const Rn=en.table("bucket_files",{bucket_file_id:ni("bucket_file_id").primaryKey().generatedByDefaultAsIdentity(),...xn,bucket_name:nt("bucket_name"),bucket_path:nt("bucket_path"),byte_size:ni("byte_size"),cloudinary_public_id:nt("cloudinary_public_id"),cloudinary_source_url:nt("cloudinary_source_url"),content_type:nt("content_type"),deprecated_fields:mi("deprecated_fields"),filename:nt("filename"),media_description:nt("media_description"),name:nt("name"),previous_downloadable_id:ni("previous_downloadable_id"),...En,...bn},e=>[p("bucket_files_cloudinary_public_id_unique").on(e.cloudinary_public_id)]);en.table("downloadables",{downloadable_id:ni("downloadable_id").notNull().generatedByDefaultAsIdentity(),...Vn,bucket_file_id:ni("bucket_file_id").notNull(),lesson_id:ni("lesson_id"),custom_title:nt("custom_title"),deprecated_fields:mi("deprecated_fields"),position:ni("position").notNull(),previous_lesson_id:ni("previous_lesson_id"),...En,...bn},e=>[Kt({columns:[e.downloadable_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"downloadables_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rn.bucket_file_id]}),Vt("downloadables_lesson_position_unique").on(e.lesson_id,e.position,e._state)]);const Mn=en.table("videos",{video_id:ni("video_id").primaryKey().generatedByDefaultAsIdentity(),...xn,cloudinary_public_id:nt("cloudinary_public_id"),cloudinary_source_url:nt("cloudinary_source_url"),contains_identifiable_face:Be("contains_identifiable_face"),deprecated_fields:mi("deprecated_fields"),duration_seconds:$i("duration_seconds"),has_bsl:Be("has_bsl"),media_description:nt("media_description"),mux_asset_id:nt("mux_asset_id"),mux_playback_id:nt("mux_playback_id"),name:nt("name"),previous_lesson_video_id:ni("previous_lesson_video_id"),previous_media_clip_ids:ni("previous_media_clip_ids").array(),raw_mux_data:mi("raw_mux_data"),signed_stream_id:nt("signed_stream_id"),title:nt("title"),url:nt("url"),video_uid:Le("video_uid",{length:16}),...En,...bn},e=>[p("videos_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("videos_cloudinary_source_url_unique").on(e.cloudinary_source_url)]);en.table("lesson_videos",{lesson_video_id:ni("lesson_video_id").notNull().generatedByDefaultAsIdentity(),...Vn,lesson_id:ni("lesson_id"),sign_language_video_id:ni("sign_language_video_id"),video_id:ni("video_id"),previous_lesson_id:ni("previous_lesson_id"),...En,...bn},e=>[Kt({columns:[e.lesson_video_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({columns:[e.video_id],foreignColumns:[Mn.video_id]}),m({name:"lesson_videos_sign_lang_video_fk",columns:[e.sign_language_video_id],foreignColumns:[Mn.video_id]}),Vt("lesson_videos_lesson_unique").on(e.lesson_id,e._state),ge("lesson_videos_video_required_published",t.sql`${e._state} <> 'published' or ${e.video_id} is not null`)]);const Wn=en.table("media_clip_collection",{media_clip_collection_id:ni("media_clip_collection_id").notNull().generatedByDefaultAsIdentity(),...Vn,lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),...En,...bn},e=>[Kt({columns:[e.media_clip_collection_id,e._state]}),m({name:"mc_collection_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),Vt("media_clip_collection_lesson_unique").on(e.lesson_id,e._state)]),Hn=en.table("sounds",{sound_id:ni("sound_id").primaryKey().generatedByDefaultAsIdentity(),...xn,cloudinary_public_id:nt("cloudinary_public_id"),cloudinary_source_url:nt("cloudinary_source_url"),duration_seconds:$i("duration_seconds"),media_description:nt("media_description"),mux_asset_id:nt("mux_asset_id"),mux_playback_id:nt("mux_playback_id"),name:nt("name"),previous_media_clip_ids:ni("previous_media_clip_ids").array(),title:nt("title"),...En,...bn},e=>[p("sounds_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("sounds_cloudinary_source_url_unique").on(e.cloudinary_source_url)]);en.table("media_clips",{media_clip_id:ni("media_clip_id").notNull().generatedByDefaultAsIdentity(),...Vn,media_clip_collection_id:ni("media_clip_collection_id").notNull(),sound_id:ni("sound_id"),video_id:ni("video_id"),clip_section:pn("clip_section").notNull(),custom_title:nt("custom_title"),lesson_outline_index:ni("lesson_outline_index"),media_kind:mn("media_kind"),position:ni("position").notNull(),...En,...bn},e=>[Kt({columns:[e.media_clip_id,e._state]}),m({name:"media_clips_mc_collection_fk",columns:[e.media_clip_collection_id,e._state],foreignColumns:[Wn.media_clip_collection_id,Wn._state]}),m({columns:[e.sound_id],foreignColumns:[Hn.sound_id]}),m({columns:[e.video_id],foreignColumns:[Mn.video_id]}),ge("media_clip_video_or_sound",t.sql`(video_id IS NOT NULL AND sound_id IS NULL) OR (video_id IS NULL AND sound_id IS NOT NULL)`),ge("media_clip_section_lesson_outline",t.sql`(clip_section = 'lesson_outline' AND lesson_outline_index IS NOT NULL)
|
|
8
|
+
OR (clip_section = 'intro' AND lesson_outline_index IS NULL)`),Vt("media_clips_lo_position_unique").on(e.media_clip_collection_id,e.lesson_outline_index,e.position,e._state).where(t.sql`${e.clip_section} = 'lesson_outline'`),Vt("media_clips_intro_position_unique").on(e.media_clip_collection_id,e.position,e._state).where(t.sql`${e.clip_section} = 'intro'`)]);const Gn=en.table("images",{image_id:ni("image_id").primaryKey().generatedByDefaultAsIdentity(),...xn,cloudinary_public_id:nt("cloudinary_public_id"),cloudinary_source_url:nt("cloudinary_source_url"),contains_identifiable_face:Be("contains_identifiable_face"),height:ni("height"),media_description:nt("media_description"),name:nt("name"),width:ni("width"),...En,...bn},e=>[p("images_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("images_cloudinary_source_url_unique").on(e.cloudinary_source_url)]),Yn=en.table("questions",{question_id:ni("question_id").notNull().generatedByDefaultAsIdentity(),...Vn,stem_image_id:ni("stem_image_id"),deprecated_fields:mi("deprecated_fields"),feedback:nt("feedback"),hint:nt("hint"),question_type:un("question_type").notNull(),question_uid:Le("question_uid",{length:16}).notNull(),stem_text:nt("stem_text"),...En,...bn},e=>[Kt({columns:[e.question_id,e._state]}),m({columns:[e.stem_image_id],foreignColumns:[Gn.image_id]})]);en.table("question_options",{option_id:ni("option_id").notNull().generatedByDefaultAsIdentity(),...Vn,body_image_id:ni("body_image_id"),match_partner_image_id:ni("match_partner_image_id"),question_id:ni("question_id").notNull(),body_text:nt("body_text"),correct_order:ni("correct_order"),is_default:Be("is_default"),is_correct:Be("is_correct"),match_partner_text:nt("match_partner_text"),position:ni("position"),temporary_fields:mi("temporary_fields"),...En,...bn},e=>[Kt({columns:[e.option_id,e._state]}),m({name:"question_options_question_fk",columns:[e.question_id,e._state],foreignColumns:[Yn.question_id,Yn._state]}),m({name:"question_options_body_image_fk",columns:[e.body_image_id],foreignColumns:[Gn.image_id]}),m({name:"question_options_match_partner_image_fk",columns:[e.match_partner_image_id],foreignColumns:[Gn.image_id]})]);const Zn=en.table("units",{unit_id:ni("unit_id").notNull().generatedByDefaultAsIdentity(),...Sn,deprecated_fields:mi("deprecated_fields"),description:nt("description").notNull(),slug:nt("slug"),title:nt("title").notNull(),unit_uid:Le("unit_uid",{length:16}),why_this_why_now:nt("why_this_why_now"),...En,...bn},e=>[Kt({columns:[e.unit_id,e._state]})]);en.table("question_units",{question_id:ni("question_id").notNull(),unit_id:ni("unit_id").notNull(),...Tn,...zn,...En,...bn},e=>[Kt({name:"question_units_pk",columns:[e.question_id,e.unit_id,e._question_state,e._unit_state]}),m({name:"question_units_question_fk",columns:[e.question_id,e._question_state],foreignColumns:[Yn.question_id,Yn._state]}),m({name:"question_units_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zn.unit_id,Zn._state]}),In({name:"question_units_state_coherence",columnA:e._question_state,columnB:e._unit_state})]);const Xn=en.enum("quiz_role",["starter","exit"]),e_=en.table("quizzes",{quiz_id:ni("quiz_id").notNull().generatedByDefaultAsIdentity(),...Vn,lesson_id:ni("lesson_id"),deprecated_fields:mi("deprecated_fields"),previous_lesson_id:ni("previous_lesson_id"),quiz_answers_pdf_bucket_name:nt("quiz_answers_pdf_bucket_name"),quiz_answers_pdf_bucket_path:nt("quiz_answers_pdf_bucket_path"),quiz_pdf_bucket_name:nt("quiz_pdf_bucket_name"),quiz_pdf_bucket_path:nt("quiz_pdf_bucket_path"),quiz_role:Xn("quiz_role").notNull(),quiz_uid:Le("quiz_uid",{length:16}).notNull(),...En,...bn},e=>[Kt({columns:[e.quiz_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),Vt("quizzes_lesson_role_unique").on(e.lesson_id,e.quiz_role,e._state)]);en.table("quiz_questions",{quiz_id:ni("quiz_id").notNull(),question_id:ni("question_id").notNull(),...jn,...Tn,position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"quiz_questions_pk",columns:[e.quiz_id,e.question_id,e._quiz_state,e._question_state]}),m({name:"quiz_questions_quiz_fk",columns:[e.quiz_id,e._quiz_state],foreignColumns:[e_.quiz_id,e_._state]}),m({name:"quiz_questions_question_fk",columns:[e.question_id,e._question_state],foreignColumns:[Yn.question_id,Yn._state]}),In({name:"quiz_questions_state_coherence",columnA:e._quiz_state,columnB:e._question_state})]);const i_=en.table("urls",{url_id:ni("url_id").primaryKey().generatedByDefaultAsIdentity(),...xn,cloudinary_public_id:nt("cloudinary_public_id"),cloudinary_source_url:nt("cloudinary_source_url"),name:nt("name"),url:nt("url"),...En,...bn},e=>[p("urls_cloudinary_public_id_unique").on(e.cloudinary_public_id),p("urls_cloudinary_source_url_unique").on(e.cloudinary_source_url)]),t_=en.table("media_copyright",{media_copyright_id:ni("media_copyright_id").notNull().generatedByDefaultAsIdentity(),...Vn,bucket_file_id:ni("bucket_file_id"),image_id:ni("image_id"),sound_id:ni("sound_id"),url_id:ni("url_id"),video_id:ni("video_id"),acquisition_basis:on("acquisition_basis"),additional_restrictions:nt("additional_restrictions"),attribution:nt("attribution"),deprecated_fields:mi("deprecated_fields"),internal_notes:nt("internal_notes"),legacy_data_shape:Be("legacy_data_shape").notNull(),licence:dn("licence"),media_copyright_uid:Le("media_copyright_uid",{length:16}).notNull(),media_provenance:an("media_provenance"),media_provenance_url:nt("media_provenance_url"),permission_status:rn("permission_status"),restriction_level_override:_n("restriction_level_override"),territory_other:nt("territory_other"),territory_override:ln("territory_override"),third_party_id:nt("third_party_id"),...En,...bn},e=>[Kt({columns:[e.media_copyright_id,e._state]}),m({columns:[e.image_id],foreignColumns:[Gn.image_id]}),m({columns:[e.sound_id],foreignColumns:[Hn.sound_id]}),m({columns:[e.video_id],foreignColumns:[Mn.video_id]}),m({name:"media_copyright_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rn.bucket_file_id]}),m({columns:[e.url_id],foreignColumns:[i_.url_id]}),ge("media_copyright_has_exactly_one_media",t.sql`(image_id IS NOT NULL)::int + (sound_id IS NOT NULL)::int + (video_id IS NOT NULL)::int + (bucket_file_id IS NOT NULL)::int + (url_id IS NOT NULL)::int = 1`),p("media_copyright_image_unique").on(e.image_id,e._state),p("media_copyright_sound_unique").on(e.sound_id,e._state),p("media_copyright_video_unique").on(e.video_id,e._state),p("media_copyright_bucket_file_unique").on(e.bucket_file_id,e._state),p("media_copyright_url_unique").on(e.url_id,e._state),p("media_copyright_uid_unique").on(e.media_copyright_uid,e._state)]),s_=sn.enum("contract_territory",["worldwide","worldwide_excl_usa","worldwide_excl_canada_and_usa","uk_only","uk_and_commonwealth","uk_and_commonwealth_excl_canada","uk_and_eire"]),n_=sn.table("tpc_contracts",{tpc_contract_id:ni("tpc_contract_id").primaryKey().generatedByDefaultAsIdentity(),...xn,effective_date:He("effective_date"),end_date:He("end_date"),geo_restricted:Be().notNull().default(!1),juro_id:nt("juro_id").notNull(),juro_url:nt("juro_url"),login_required:Be().notNull().default(!1),name:nt("name").notNull(),raw_contract:mi("raw_contract"),restricted_download:Be().notNull().default(!1),restriction_level:_n(),signing_side:nt("signing_side"),territory:s_("territory"),tpc_contract_uid:Le("tpc_contract_uid",{length:16}).notNull(),...bn},()=>[]);en.table("media_copyright_tpc_contracts",{media_copyright_id:ni("media_copyright_id").notNull(),tpc_contract_id:ni("tpc_contract_id").notNull(),...Vn,...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"media_copyright_tpc_contracts_pk",columns:[e.media_copyright_id,e.tpc_contract_id,e._state]}),m({name:"media_copyright_tpc_contract_media_copyright_fk",columns:[e.media_copyright_id,e._state],foreignColumns:[t_.media_copyright_id,t_._state]}),m({name:"media_copyright_tpc_contract_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[n_.tpc_contract_id]}),m({name:"media_copyright_tpc_contracts_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]})]),en.table("gdrive_file_images",{gdrive_file_id:ni("gdrive_file_id").notNull(),image_id:ni("image_id").notNull(),...xn,...En,...bn},e=>[Kt({columns:[e.gdrive_file_id,e.image_id]}),m({name:"gdrive_file_images_gdrive_file_fk",columns:[e.gdrive_file_id],foreignColumns:[Kn.gdrive_file_id]}),m({columns:[e.image_id],foreignColumns:[Gn.image_id]})]),en.table("lesson_media",{lesson_media_id:ni("lesson_media_id").notNull().generatedByDefaultAsIdentity(),...Sn,lesson_id:ni("lesson_id").notNull(),bucket_file_id:ni("bucket_file_id"),image_id:ni("image_id"),sound_id:ni("sound_id"),url_id:ni("url_id"),video_id:ni("video_id"),...En,...bn},e=>[Kt({name:"lesson_media_pk",columns:[e.lesson_media_id,e._state]}),m({name:"lesson_media_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"lesson_media_image_fk",columns:[e.image_id],foreignColumns:[Gn.image_id]}),m({name:"lesson_media_sound_fk",columns:[e.sound_id],foreignColumns:[Hn.sound_id]}),m({name:"lesson_media_video_fk",columns:[e.video_id],foreignColumns:[Mn.video_id]}),m({name:"lesson_media_bucket_file_fk",columns:[e.bucket_file_id],foreignColumns:[Rn.bucket_file_id]}),m({name:"lesson_media_url_fk",columns:[e.url_id],foreignColumns:[i_.url_id]}),ge("lesson_media_has_exactly_one_media",t.sql`(image_id IS NOT NULL)::int + (sound_id IS NOT NULL)::int + (video_id IS NOT NULL)::int + (bucket_file_id IS NOT NULL)::int + (url_id IS NOT NULL)::int = 1`),p("lesson_media_lesson_asset_unique").on(e.lesson_id,e._state,e.image_id,e.sound_id,e.video_id,e.bucket_file_id,e.url_id).nullsNotDistinct()]);const __=en.table("works_copyright",{works_copyright_id:ni("works_copyright_id").notNull().generatedByDefaultAsIdentity(),...Sn,attribution:nt("attribution"),author:nt("author"),deprecated_fields:mi("deprecated_fields"),raw_juro_data:mi("raw_juro_data"),restriction_level:_n("restriction_level"),title:nt("title"),works_copyright_uid:Le("works_copyright_uid",{length:16}),...En,...bn},e=>[Kt({columns:[e.works_copyright_id,e._state]})]);en.table("lesson_works_copyright",{lesson_id:ni("lesson_id").notNull(),works_copyright_id:ni("works_copyright_id").notNull(),...Cn,...Dn,...En,...bn},e=>[Kt({name:"lesson_works_copyright_pk",columns:[e.lesson_id,e.works_copyright_id,e._lesson_state,e._works_copyright_state]}),m({name:"lesson_works_copyright_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"lesson_works_copyright_works_copyright_fk",columns:[e.works_copyright_id,e._works_copyright_state],foreignColumns:[__.works_copyright_id,__._state]}),Qn({name:"lesson_works_copyright_state_coherence",columnA:e._lesson_state,columnB:e._works_copyright_state,allow:[["draft","published"]]})]);const a_=en.table("features",{feature_id:ni("feature_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key:nt("key").notNull(),...En,...bn},e=>[p("features_key_unique").on(e.key)]);en.table("lesson_features",{lesson_id:ni("lesson_id").notNull(),feature_id:ni("feature_id").notNull(),...Vn,value:nt("value"),...En,...bn},e=>[Kt({columns:[e.lesson_id,e.feature_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"lesson_features_feature_fk",columns:[e.feature_id],foreignColumns:[a_.feature_id]})]),en.table("sound_transcripts",{sound_id:ni("sound_id").notNull(),...Sn,bad_language_detected:Be("bad_language_detected"),deprecated_fields:mi("deprecated_fields"),inappropriate_words:mi("inappropriate_words"),language_approved:Be("language_approved"),transcript:nt("transcript"),transcript_vtt_url:nt("transcript_vtt_url"),...En,...bn},e=>[Kt({columns:[e.sound_id,e._state]}),m({columns:[e.sound_id],foreignColumns:[Hn.sound_id]})]),en.table("video_captions",{video_id:ni("video_id").notNull(),...Sn,bad_language_detected:Be("bad_language_detected"),deprecated_fields:mi("deprecated_fields"),inappropriate_words:mi("inappropriate_words"),language_approved:Be("language_approved"),transcript:nt("transcript"),transcript_vtt_url:nt("transcript_vtt_url"),...En,...bn},e=>[Kt({columns:[e.video_id,e._state]}),m({columns:[e.video_id],foreignColumns:[Mn.video_id]})]),en.table("works_copyright_tpc_contracts",{works_copyright_id:ni("works_copyright_id").notNull(),tpc_contract_id:ni("tpc_contract_id").notNull(),...Vn,...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"works_copyright_tpc_contracts_pk",columns:[e.works_copyright_id,e.tpc_contract_id,e._state]}),m({name:"works_copyright_tpc_contract_works_copyright_fk",columns:[e.works_copyright_id,e._state],foreignColumns:[__.works_copyright_id,__._state]}),m({name:"works_copyright_tpc_contract_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[n_.tpc_contract_id]}),m({name:"works_copyright_tpc_contracts_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]})]),en.table("videos_works_copyright",{video_id:ni("video_id").notNull(),works_copyright_id:ni("works_copyright_id").notNull(),...Sn,...En,...bn},e=>[Kt({columns:[e.video_id,e.works_copyright_id,e._state]}),m({name:"videos_works_copyright_video_fk",columns:[e.video_id],foreignColumns:[Mn.video_id]}),m({name:"videos_works_copyright_works_copyright_fk",columns:[e.works_copyright_id,e._state],foreignColumns:[__.works_copyright_id,__._state]})]);const o_=en.table("supervision_levels",{supervision_level_id:ni("supervision_level_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),supervision_level_rating:ni("supervision_level_rating"),title:nt("title").notNull(),...En,...bn}),r_=en.table("content_guidance",{content_guidance_id:ni("content_guidance_id").primaryKey().generatedByDefaultAsIdentity(),...xn,supervision_level_id:ni("supervision_level_id").notNull(),content_guidance_area:nt("content_guidance_area"),content_guidance_code:nt("content_guidance_code"),content_guidance_description:nt("content_guidance_description"),content_guidance_label:nt("content_guidance_label"),deprecated_fields:mi("deprecated_fields"),...En,...bn},e=>[m({name:"content_guid_super_level_fk",columns:[e.supervision_level_id],foreignColumns:[o_.supervision_level_id]})]),l_=en.table("key_stages",{key_stage_id:ni("key_stage_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),key_stage:nt("key_stage"),slug:nt("slug"),...En,...bn}),d_=en.table("phases",{phase_id:ni("phase_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),phase:nt("phase"),slug:nt("slug"),...En,...bn}),u_=en.table("subjects",{subject_id:ni("subject_id").primaryKey().generatedByDefaultAsIdentity(),...xn,subject_parent_id:ni("subject_parent_id"),deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),non_curriculum:Be("non_curriculum"),slug:nt("slug"),subject:nt("subject"),...En,...bn},e=>[m({name:"subjects_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[e.subject_id]})]),c_=en.table("years",{year_id:ni("year_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key_stage_id:ni("key_stage_id").notNull(),phase_id:ni("phase_id").notNull(),deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),slug:nt("slug"),year:nt("year"),...En,...bn},e=>[m({columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({columns:[e.phase_id],foreignColumns:[d_.phase_id]})]);en.table("content_guidance_scopes",{scope_id:ni("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xn,content_guidance_id:ni("content_guidance_id").notNull(),key_stage_id:ni("key_stage_id"),phase_id:ni("phase_id"),subject_id:ni("subject_id"),subject_parent_id:ni("subject_parent_id"),year_id:ni("year_id"),...En,...bn},e=>[m({name:"content_guid_scopes_content_guid_fk",columns:[e.content_guidance_id],foreignColumns:[r_.content_guidance_id]}),m({name:"content_guid_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"content_guid_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[u_.subject_id]}),m({name:"content_guid_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"content_guid_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]})]);const m_=en.table("exam_board_specs",{exam_board_spec_id:ni("exam_board_spec_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),title:nt("title").notNull(),...En,...bn});en.table("exam_board_spec_scopes",{scope_id:ni("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xn,exam_board_spec_id:ni("exam_board_spec_id").notNull(),key_stage_id:ni("key_stage_id"),phase_id:ni("phase_id"),subject_id:ni("subject_id"),subject_parent_id:ni("subject_parent_id"),year_id:ni("year_id"),...En,...bn},e=>[m({name:"exam_spec_scopes_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[m_.exam_board_spec_id]}),m({name:"exam_spec_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"exam_spec_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[u_.subject_id]}),m({name:"exam_spec_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"exam_spec_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]})]),en.table("lesson_content_guidance",{lesson_id:ni("lesson_id").notNull(),content_guidance_id:ni("content_guidance_id").notNull(),...Vn,position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"lesson_content_guid_pk",columns:[e.lesson_id,e.content_guidance_id,e._state]}),m({name:"lesson_content_guid_lesson_fk",columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({name:"lesson_content_guid_content_guid_fk",columns:[e.content_guidance_id],foreignColumns:[r_.content_guidance_id]})]);const p_=en.table("tags",{tag_id:ni("tag_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),tag_category:cn("tag_category"),title:nt("title").notNull(),...En,...bn});en.table("lesson_tags",{lesson_id:ni("lesson_id").notNull(),tag_id:ni("tag_id").notNull(),...Vn,position:ni("position").notNull(),...En,...bn},e=>[Kt({columns:[e.lesson_id,e.tag_id,e._state]}),m({columns:[e.lesson_id,e._state],foreignColumns:[Un.lesson_id,Un._state]}),m({columns:[e.tag_id],foreignColumns:[p_.tag_id]})]);const g_=en.table("national_curriculum",{national_curriculum_id:ni("national_curriculum_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),title:nt("title").notNull(),...En,...bn});en.table("national_curriculum_scopes",{scope_id:ni("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key_stage_id:ni("key_stage_id"),national_curriculum_id:ni("national_curriculum_id").notNull(),phase_id:ni("phase_id"),subject_id:ni("subject_id"),subject_parent_id:ni("subject_parent_id"),year_id:ni("year_id"),...En,...bn},e=>[m({name:"nat_curric_scopes_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[g_.national_curriculum_id]}),m({name:"nat_curric_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"nat_curric_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[u_.subject_id]}),m({name:"nat_curric_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"nat_curric_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({name:"nat_curric_scopes_year_fk",columns:[e.year_id],foreignColumns:[c_.year_id]})]);const f_=en.table("subject_categories",{subject_category_id:ni("subject_category_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),slug:nt("slug"),title:nt("title").notNull(),...En,...bn});en.table("subject_category_scopes",{scope_id:ni("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key_stage_id:ni("key_stage_id"),phase_id:ni("phase_id"),subject_category_id:ni("subject_category_id").notNull(),subject_id:ni("subject_id"),subject_parent_id:ni("subject_parent_id"),year_id:ni("year_id"),...En,...bn},e=>[m({name:"subj_cat_scopes_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[f_.subject_category_id]}),m({name:"subj_cat_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"subj_cat_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[u_.subject_id]}),m({name:"subj_cat_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"subj_cat_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]})]),en.table("tag_scopes",{scope_id:ni("scope_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key_stage_id:ni("key_stage_id"),phase_id:ni("phase_id"),subject_id:ni("subject_id"),subject_parent_id:ni("subject_parent_id"),tag_id:ni("tag_id").notNull(),year_id:ni("year_id"),...En,...bn},e=>[m({columns:[e.tag_id],foreignColumns:[p_.tag_id]}),m({columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"tag_scopes_subj_parent_fk",columns:[e.subject_parent_id],foreignColumns:[u_.subject_id]}),m({columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"tag_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]})]),en.table("unit_exam_board_specs",{unit_id:ni("unit_id").notNull(),exam_board_spec_id:ni("exam_board_spec_id").notNull(),...Vn,position:ni("position").notNull(),...En,...bn},e=>[Kt({columns:[e.unit_id,e.exam_board_spec_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),m({name:"unit_exam_spec_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[m_.exam_board_spec_id]})]),en.table("unit_national_curriculum",{unit_id:ni("unit_id").notNull(),national_curriculum_id:ni("national_curriculum_id").notNull(),...Vn,position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"unit_nat_curric_pk",columns:[e.unit_id,e.national_curriculum_id,e._state]}),m({name:"unit_nat_curric_unit_fk",columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),m({name:"unit_nat_curric_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[g_.national_curriculum_id]})]),en.table("unit_subject_categories",{unit_id:ni("unit_id").notNull(),subject_category_id:ni("subject_category_id").notNull(),...Vn,position:ni("position").notNull(),...En,...bn},e=>[Kt({columns:[e.unit_id,e.subject_category_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),m({name:"unit_subj_cat_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[f_.subject_category_id]})]);const h_=en.table("exam_boards",{exam_board_id:ni("exam_board_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),exam_board:nt("exam_board"),global_position:ni("global_position").notNull(),slug:nt("slug"),...En,...bn}),v_=en.table("pathways",{pathway_id:ni("pathway_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),pathway:nt("pathway"),slug:nt("slug"),...En,...bn}),y_=en.table("tiers",{tier_id:ni("tier_id").primaryKey().generatedByDefaultAsIdentity(),...xn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),global_position:ni("global_position").notNull(),slug:nt("slug"),tier:nt("tier"),...En,...bn}),b_=en.table("unit_variants",{unit_variant_id:ni("unit_variant_id").notNull().generatedByDefaultAsIdentity(),...Vn,exam_board_id:ni("exam_board_id"),pathway_id:ni("pathway_id"),subject_id:ni("subject_id"),tier_id:ni("tier_id"),unit_id:ni("unit_id").notNull(),deprecated_fields:mi("deprecated_fields"),description_override:nt("description_override"),optionality:nt("optionality"),planned_number_of_lessons_override:ni("planned_number_of_lessons_override"),prior_knowledge_requirements_override:nt("prior_knowledge_requirements_override").array(),title_override:nt("title_override"),unit_variant_uid:Le("unit_variant_uid",{length:16}),why_this_why_now_override:nt("why_this_why_now_override"),...En,...bn},e=>[Kt({columns:[e.unit_variant_id,e._state]}),m({name:"unit_variants_exam_board_fk",columns:[e.exam_board_id],foreignColumns:[h_.exam_board_id]}),m({columns:[e.pathway_id],foreignColumns:[v_.pathway_id]}),m({columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({columns:[e.tier_id],foreignColumns:[y_.tier_id]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),p("unit_variants_unit_scope_unique").on(e.unit_id,e.subject_id,e.tier_id,e.exam_board_id,e.pathway_id,e.optionality,e._state).nullsNotDistinct()]);en.table("unit_variant_exam_board_specs_override",{unit_variant_id:ni("unit_variant_id").notNull(),exam_board_spec_id:ni("exam_board_spec_id").notNull(),...Vn,position:ni("position").notNull(),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"unit_variant_exam_board_specs_override_pk",columns:[e.unit_variant_id,e.exam_board_spec_id,e._state]}),m({name:"unit_var_exam_spec_ovr_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"unit_var_exam_spec_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[b_.unit_variant_id,b_._state]}),m({name:"unit_var_exam_spec_ovr_exam_spec_fk",columns:[e.exam_board_spec_id],foreignColumns:[m_.exam_board_spec_id]})]),en.table("unit_variant_national_curriculum_override",{unit_variant_id:ni("unit_variant_id").notNull(),national_curriculum_id:ni("national_curriculum_id").notNull(),...Vn,position:ni("position").notNull(),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"unit_variant_national_curriculum_override_pk",columns:[e.unit_variant_id,e.national_curriculum_id,e._state]}),m({name:"unit_var_nat_curric_ovr_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"unit_var_nat_curric_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[b_.unit_variant_id,b_._state]}),m({name:"unit_var_nat_curric_ovr_nat_curric_fk",columns:[e.national_curriculum_id],foreignColumns:[g_.national_curriculum_id]})]),en.table("unit_variant_subject_categories_override",{unit_variant_id:ni("unit_variant_id").notNull(),subject_category_id:ni("subject_category_id").notNull(),...Vn,position:ni("position").notNull(),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"unit_variant_subject_categories_override_pk",columns:[e.unit_variant_id,e.subject_category_id,e._state]}),m({name:"unit_var_subj_cat_ovr_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"unit_var_subj_cat_ovr_unit_var_fk",columns:[e.unit_variant_id,e._state],foreignColumns:[b_.unit_variant_id,b_._state]}),m({name:"unit_var_subj_cat_ovr_subj_cat_fk",columns:[e.subject_category_id],foreignColumns:[f_.subject_category_id]})]);const w_=en.table("actions",{action_id:ni("action_id").primaryKey().generatedByDefaultAsIdentity(),...xn,key:nt("key").notNull(),...En,...bn},e=>[p("actions_key_unique").on(e.key)]),N_=en.table("overrides_and_exceptions",{overrides_and_exceptions_id:ni("overrides_and_exceptions_id").notNull().generatedByDefaultAsIdentity(),...Sn,description:nt("description"),temporary_fields:mi("temporary_fields"),used_by_queries:mi("used_by_queries").notNull().default([]),...En,...bn},e=>[Kt({columns:[e.overrides_and_exceptions_id,e._state]})]);en.table("overrides_and_exceptions_actions",{overrides_and_exceptions_id:ni("overrides_and_exceptions_id").notNull(),action_id:ni("action_id").notNull(),...Sn,value:mi("value").notNull(),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"ovr_exc_actions_pk",columns:[e.overrides_and_exceptions_id,e.action_id,e._state]}),m({name:"ovr_exc_actions_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"ovr_exc_actions_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[N_.overrides_and_exceptions_id,N_._state]}),m({name:"ovr_exc_actions_action_fk",columns:[e.action_id],foreignColumns:[w_.action_id]})]),en.table("overrides_and_exceptions_feature_scopes",{overrides_and_exceptions_id:ni("overrides_and_exceptions_id").notNull(),condition_id:ni("condition_id").notNull(),feature_id:ni("feature_id").notNull(),...Sn,value:nt("value").notNull(),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"ovr_exc_feature_scopes_pk",columns:[e.overrides_and_exceptions_id,e.condition_id,e.feature_id,e._state]}),m({name:"ovr_exc_feature_scopes_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"ovr_exc_feature_scopes_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[N_.overrides_and_exceptions_id,N_._state]}),m({name:"ovr_exc_feature_scopes_feature_fk",columns:[e.feature_id],foreignColumns:[a_.feature_id]})]),en.table("overrides_and_exceptions_programme_scopes",{scope_id:ni("scope_id").notNull().generatedByDefaultAsIdentity(),...Sn,key_stage_id:ni("key_stage_id"),overrides_and_exceptions_id:ni("overrides_and_exceptions_id").notNull(),pathway_id:ni("pathway_id"),phase_id:ni("phase_id"),subject_id:ni("subject_id"),tier_id:ni("tier_id"),legacy:Be("legacy"),subject_slug:nt("subject_slug"),...En,_release_id:ni("_release_id"),...bn},e=>[Kt({name:"ovr_exc_programme_scopes_pk",columns:[e.scope_id,e._state]}),m({name:"ovr_exc_programme_scopes_release_fk",columns:[e._release_id],foreignColumns:[kn.release_id]}),m({name:"ovr_exc_programme_scopes_ovr_exc_fk",columns:[e.overrides_and_exceptions_id,e._state],foreignColumns:[N_.overrides_and_exceptions_id,N_._state]}),m({name:"ovr_exc_programme_scopes_key_stage_fk",columns:[e.key_stage_id],foreignColumns:[l_.key_stage_id]}),m({name:"ovr_exc_programme_scopes_pathway_fk",columns:[e.pathway_id],foreignColumns:[v_.pathway_id]}),m({name:"ovr_exc_programme_scopes_phase_fk",columns:[e.phase_id],foreignColumns:[d_.phase_id]}),m({name:"ovr_exc_programme_scopes_subject_fk",columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({name:"ovr_exc_programme_scopes_tier_fk",columns:[e.tier_id],foreignColumns:[y_.tier_id]})]),en.table("redirects",{entity_id:ni("entity_id").notNull(),entity_source:fn("entity_source").notNull(),...Vn,description:nt("description"),redirect_entity_id:ni("redirect_entity_id"),redirect_entity_source:fn("redirect_entity_source"),redirect_type:gn("redirect_type").notNull(),redirect_url:nt("redirect_url"),...En,...bn},e=>[Kt({columns:[e.entity_id,e.entity_source,e._state]}),ge("redirect_has_exactly_one_target",t.sql`(redirect_url IS NOT NULL)::int + (redirect_entity_id IS NOT NULL)::int = 1`),ge("redirect_entity_ref_complete",t.sql`(redirect_entity_id IS NULL) = (redirect_entity_source IS NULL)`)]);const k_=en.table("choices",{choice_id:ni("choice_id").notNull().generatedByDefaultAsIdentity(),...Vn,unit_id:ni("unit_id").notNull(),temporary_fields:mi("temporary_fields"),...En,...bn},e=>[Kt({columns:[e.choice_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]})]);en.table("choices_unit_variants",{unit_variant_id:ni("unit_variant_id").notNull(),choice_id:ni("choice_id").notNull(),...Bn,...An,position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"choices_unit_var_pk",columns:[e.unit_variant_id,e.choice_id,e._unit_variant_state,e._choice_state]}),m({name:"choices_unit_var_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[b_.unit_variant_id,b_._state]}),m({name:"choices_unit_var_choice_fk",columns:[e.choice_id,e._choice_state],foreignColumns:[k_.choice_id,k_._state]}),In({name:"choices_unit_var_state_coherence",columnA:e._unit_variant_state,columnB:e._choice_state})]);const S_=en.table("programmes",{programme_id:ni("programme_id").notNull().generatedByDefaultAsIdentity(),...Vn,exam_board_id:ni("exam_board_id"),pathway_id:ni("pathway_id"),subject_id:ni("subject_id").notNull(),tier_id:ni("tier_id"),year_id:ni("year_id").notNull(),deprecated_fields:mi("deprecated_fields"),legacy:Be("legacy").notNull().default(!1),national_curriculum_content:Be("national_curriculum_content").notNull().default(!1),programme_uid:Le("programme_uid",{length:16}),...En,...bn},e=>[Kt({columns:[e.programme_id,e._state]}),m({columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]}),m({columns:[e.tier_id],foreignColumns:[y_.tier_id]}),m({name:"programmes_exam_board_fk",columns:[e.exam_board_id],foreignColumns:[h_.exam_board_id]}),m({columns:[e.pathway_id],foreignColumns:[v_.pathway_id]}),p("programmes_factor_scope_unique").on(e.subject_id,e.year_id,e.tier_id,e.exam_board_id,e.pathway_id,e.legacy,e._state).nullsNotDistinct()]);en.table("inclusions",{programme_id:ni("programme_id").notNull(),position:ni("position").notNull(),...qn,...On,...Ln,choice_id:ni("choice_id"),unit_variant_id:ni("unit_variant_id"),...En,...bn},e=>[Kt({name:"inclusions_pk",columns:[e.programme_id,e.position,e._programme_state]}),ge("inclusions_xor_variant_choice",t.sql`num_nonnulls(${e.unit_variant_id}, ${e.choice_id}) = 1`),ge("inclusions_choice_state_matches",t.sql`(${e.choice_id} is null) = (${e._choice_state} is null)`),ge("inclusions_unit_variant_state_matches",t.sql`(${e.unit_variant_id} is null) = (${e._unit_variant_state} is null)`),Vt("inclusions_choice_unique").on(e.choice_id,e._choice_state).where(t.sql`${e.choice_id} is not null`),Vt("inclusions_programme_unit_variant_unique").on(e.programme_id,e.unit_variant_id,e._programme_state,e._unit_variant_state).where(t.sql`${e.unit_variant_id} is not null`),m({name:"inclusions_programme_fk",columns:[e.programme_id,e._programme_state],foreignColumns:[S_.programme_id,S_._state]}),m({name:"inclusions_choice_fk",columns:[e.choice_id,e._choice_state],foreignColumns:[k_.choice_id,k_._state]}),m({name:"inclusions_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[b_.unit_variant_id,b_._state]}),Fn({name:"inclusions_choice_state_coherence",columnA:e._programme_state,columnB:e._choice_state}),Fn({name:"inclusions_unit_var_state_coherence",columnA:e._programme_state,columnB:e._unit_variant_state})]);const x_=en.table("subject_phases",{subject_id:ni("subject_id").notNull(),phase_id:ni("phase_id").notNull(),...Vn,curriculum_intent:nt("curriculum_intent"),deprecated_fields:mi("deprecated_fields"),prior_knowledge_requirements:Be("prior_knowledge_requirements").notNull().default(!1),related_units:Be("related_units").notNull().default(!1),unit_description:Be("unit_description").notNull().default(!1),...En,...bn},e=>[Kt({columns:[e.subject_id,e.phase_id,e._state]}),m({columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({columns:[e.phase_id],foreignColumns:[d_.phase_id]})]),A_=en.table("threads",{thread_id:ni("thread_id").notNull().generatedByDefaultAsIdentity(),...Sn,deprecated_fields:mi("deprecated_fields"),description:nt("description"),slug:nt("slug"),thread_uid:Le("thread_uid",{length:16}),title:nt("title"),...En,...bn},e=>[Kt({columns:[e.thread_id,e._state]})]);en.table("subject_phase_threads",{subject_id:ni("subject_id").notNull(),phase_id:ni("phase_id").notNull(),thread_id:ni("thread_id").notNull(),...$n,...Pn,deprecated_fields:mi("deprecated_fields"),position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"subject_phase_threads_pk",columns:[e.subject_id,e.phase_id,e.thread_id,e._subject_phase_state,e._thread_state]}),m({name:"subject_phase_threads_subject_phase_fk",columns:[e.subject_id,e.phase_id,e._subject_phase_state],foreignColumns:[x_.subject_id,x_.phase_id,x_._state]}),m({name:"subject_phase_threads_thread_fk",columns:[e.thread_id,e._thread_state],foreignColumns:[A_.thread_id,A_._state]}),In({name:"subject_phase_threads_state_coherence",columnA:e._subject_phase_state,columnB:e._thread_state})]),en.table("unit_threads",{thread_id:ni("thread_id").notNull(),unit_id:ni("unit_id").notNull(),...Pn,...zn,deprecated_fields:mi("deprecated_fields"),position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"unit_threads_pk",columns:[e.thread_id,e.unit_id,e._thread_state,e._unit_state]}),m({name:"unit_threads_thread_fk",columns:[e.thread_id,e._thread_state],foreignColumns:[A_.thread_id,A_._state]}),m({name:"unit_threads_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zn.unit_id,Zn._state]}),In({name:"unit_threads_state_coherence",columnA:e._thread_state,columnB:e._unit_state})]),en.table("unit_catalogue",{subject_id:ni("subject_id").notNull(),year_id:ni("year_id").notNull(),unit_id:ni("unit_id").notNull(),...Vn,...En,...bn},e=>[Kt({columns:[e.subject_id,e.year_id,e.unit_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),m({columns:[e.subject_id],foreignColumns:[u_.subject_id]}),m({columns:[e.year_id],foreignColumns:[c_.year_id]})]),en.table("unit_lessons",{unit_id:ni("unit_id").notNull(),lesson_id:ni("lesson_id").notNull(),...zn,...Cn,position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"unit_lessons_pk",columns:[e.unit_id,e.lesson_id,e._unit_state,e._lesson_state]}),m({name:"unit_lessons_unit_fk",columns:[e.unit_id,e._unit_state],foreignColumns:[Zn.unit_id,Zn._state]}),m({name:"unit_lessons_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Un.lesson_id,Un._state]}),In({name:"unit_lessons_state_coherence",columnA:e._unit_state,columnB:e._lesson_state})]),en.table("unit_variant_lessons",{unit_variant_id:ni("unit_variant_id").notNull(),lesson_id:ni("lesson_id").notNull(),...Bn,...Cn,deprecated_fields:mi("deprecated_fields"),position:ni("position").notNull(),...En,...bn},e=>[Kt({name:"unit_var_lessons_pk",columns:[e.unit_variant_id,e.lesson_id,e._unit_variant_state,e._lesson_state]}),m({name:"unit_var_lessons_unit_var_fk",columns:[e.unit_variant_id,e._unit_variant_state],foreignColumns:[b_.unit_variant_id,b_._state]}),m({name:"unit_var_lessons_lesson_fk",columns:[e.lesson_id,e._lesson_state],foreignColumns:[Un.lesson_id,Un._state]}),In({name:"unit_var_lessons_state_coherence",columnA:e._unit_variant_state,columnB:e._lesson_state})]),en.table("unit_features",{unit_id:ni("unit_id").notNull(),feature_id:ni("feature_id").notNull(),...Vn,value:nt("value"),...En,...bn},e=>[Kt({columns:[e.unit_id,e.feature_id,e._state]}),m({columns:[e.unit_id,e._state],foreignColumns:[Zn.unit_id,Zn._state]}),m({columns:[e.feature_id],foreignColumns:[a_.feature_id]})]);const C_=sn.enum("lesson_component_operation_status_enum",["api_neutral","api_in_progress","api_failed","ingest_queued","ingest_in_progress","ingest_failed","ingest_completed"]),q_=sn.enum("lesson_component_status_retirement_enum",["superseded","draft_discarded","component_expired","component_removed","orphaned"]);sn.table("lesson_component_status",{lesson_component_status_id:gt("lesson_component_status_id").primaryKey().defaultRandom(),lesson_component_id:ni("lesson_component_id").notNull(),lesson_component_type:yn("lesson_component_type").notNull(),active_media_id:ni("active_media_id"),active_media_type:vn("active_media_type"),last_error_location:nt("last_error_location"),last_error_message:nt("last_error_message"),last_error_timestamp:ct("last_error_timestamp"),last_ingest_id:gt("last_ingest_id"),operation_status:C_("operation_status").notNull().default("api_neutral"),previous_media_id:ni("previous_media_id"),previous_media_type:vn("previous_media_type"),retired_at:ct("retired_at",{withTimezone:!0}),retired_reason:q_("retired_reason"),...bn},e=>[ge("lesson_comp_status_retired_both",t.sql`(${e.retired_at} is null) = (${e.retired_reason} is null)`),Vt("lesson_comp_status_live_unq").on(e.lesson_component_id,e.lesson_component_type).where(t.sql`${e.retired_at} is null`)]);const T_=sn.enum("lesson_status_enum",["api_neutral","ingest_queued","ingest_in_progress","ingest_complete","ingest_failed"]);sn.table("lesson_status",{lesson_id:ni("lesson_id").primaryKey(),approved:Be("approved").notNull().default(!1),last_approved:ct("last_approved"),last_error_location:nt("last_error_location"),last_error_message:nt("last_error_message"),last_error_timestamp:ct("last_error_timestamp"),status:T_("status").notNull().default("api_neutral"),...bn});const j_=sn.enum("media_status_enum",["neutral","in_progress","failed"]),$_=sn.enum("media_status_retirement_enum",["superseded","media_retired","orphaned"]);sn.table("media_status",{media_status_id:gt("media_status_id").primaryKey().defaultRandom(),media_id:ni("media_id").notNull(),media_type:vn("media_type").notNull(),last_error_location:nt("last_error_location"),last_error_message:nt("last_error_message"),last_error_timestamp:ct("last_error_timestamp"),last_lesson_component_id:ni("last_lesson_component_id"),last_lesson_component_type:yn("last_lesson_component_type"),retired_at:ct("retired_at",{withTimezone:!0}),retired_reason:$_("retired_reason"),status:j_("status").notNull().default("neutral"),...bn},e=>[ge("media_status_retired_both",t.sql`(${e.retired_at} is null) = (${e.retired_reason} is null)`),Vt("media_status_live_unq").on(e.media_id,e.media_type).where(t.sql`${e.retired_at} is null`)]),sn.table("mutations_log",{mutations_log_id:gt("mutations_log_id").primaryKey().defaultRandom(),actor_role:nt("actor_role"),actor_type:nt("actor_type"),app_id:nt("app_id"),changes:mi("changes").notNull(),operation:hn("operation").notNull(),record_key:mi("record_key").notNull(),table_name:nt("table_name").notNull(),...wn},e=>[Et("idx_mutations_log_record_key").using("gin",e.record_key)]),sn.table("release_snapshots",{release_snapshot_id:gt("release_snapshot_id").primaryKey().defaultRandom(),_release_id:ni("_release_id"),source_created_at:ct("source_created_at"),source_id:ni("source_id"),source_row:mi("source_row"),source_schema:nt("source_schema").default(""),source_state:nn("source_state").notNull(),source_table:nt("source_table").default(""),source_uid:Le("source_uid",{length:16}),source_updated_at:ct("source_updated_at")},e=>[m({columns:[e._release_id],foreignColumns:[kn.release_id]}),Et("release_snapshots_source_idx").on(e.source_schema,e.source_table,e.source_id),Et("release_snapshots_release_idx").on(e._release_id)]);const P_=sn.enum("contract_log_event_type_enum",["works_change","contract_change","works_added_to_contract"]);sn.table("tpc_contract_log",{tpc_contract_log_id:ni("tpc_contract_log_id").primaryKey().generatedByDefaultAsIdentity(),tpc_contract_id:ni("tpc_contract_id").notNull(),changed_at:ct("changed_at",{withTimezone:!0}).notNull(),event_type:P_("event_type").notNull(),payload:mi("payload")},e=>[m({name:"tpc_contract_log_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[n_.tpc_contract_id]})]);const z_=sn.enum("restrictions_type_enum",["Restrictions 1","Restrictions 2","Restrictions 3","Restrictions 4","Restrictions 5","Restrictions 6","Restrictions 7","Additional Restrictions"]),B_=sn.table("tpc_restriction_definitions",{tpc_restriction_definition_id:ni("tpc_restriction_definition_id").primaryKey().generatedByDefaultAsIdentity(),restriction_text:nt("restriction_text").notNull(),type:z_("type").notNull(),...bn},e=>[p("tpc_restriction_definitions_type_unique").on(e.type,e.restriction_text)]);sn.table("tpc_restrictions",{tpc_contract_id:ni("tpc_contract_id").notNull(),tpc_restriction_definition_id:ni("tpc_restriction_definition_id").notNull(),...Vn,restriction_override:nt("restriction_override"),...bn},e=>[Kt({name:"tpc_restrictions_pk",columns:[e.tpc_contract_id,e.tpc_restriction_definition_id,e._state]}),m({name:"tpc_restrictions_tpc_contract_fk",columns:[e.tpc_contract_id],foreignColumns:[n_.tpc_contract_id]}),m({name:"tpc_restrictions_tpc_restriction_definition_fk",columns:[e.tpc_restriction_definition_id],foreignColumns:[B_.tpc_restriction_definition_id]})]),tn.view("sub_published_documents_with_release_by_lesson",{document_id:ni("document_id").notNull(),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}).notNull(),lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),gdrive_file_id:ni("gdrive_file_id").notNull(),gdrive_files__epoch:nt("gdrive_files__epoch"),gdrive_files__google_drive_id:nt("gdrive_files__google_drive_id").notNull(),gdrive_files__google_drive_url:nt("gdrive_files__google_drive_url").notNull(),gdrive_files__opendocument_presentation_bucket_name:nt("gdrive_files__opendocument_presentation_bucket_name"),gdrive_files__opendocument_presentation_bucket_path:nt("gdrive_files__opendocument_presentation_bucket_path"),gdrive_files__opendocument_text_bucket_name:nt("gdrive_files__opendocument_text_bucket_name"),gdrive_files__opendocument_text_bucket_path:nt("gdrive_files__opendocument_text_bucket_path"),gdrive_files__pdf_bucket_name:nt("gdrive_files__pdf_bucket_name"),gdrive_files__pdf_bucket_path:nt("gdrive_files__pdf_bucket_path"),gdrive_files__powerpoint_bucket_name:nt("gdrive_files__powerpoint_bucket_name"),gdrive_files__powerpoint_bucket_path:nt("gdrive_files__powerpoint_bucket_path"),gdrive_files__word_bucket_name:nt("gdrive_files__word_bucket_name"),gdrive_files__word_bucket_path:nt("gdrive_files__word_bucket_path"),releases__approved:Be("releases__approved"),releases__description:nt("releases__description"),releases__estimated_release_date:He("releases__estimated_release_date"),releases__name:nt("releases__name"),releases__notes:nt("releases__notes"),releases__release_type:Nn("releases__release_type"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}).notNull(),updated_at:ct("updated_at",{withTimezone:!0}).notNull(),releases__created_at:ct("releases__created_at",{withTimezone:!0}),releases__updated_at:ct("releases__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
9
9
|
SELECT
|
|
10
10
|
d.document_id,
|
|
11
11
|
d.document_type,
|
|
12
12
|
d.document_uid,
|
|
13
13
|
d.lesson_id,
|
|
14
14
|
d.previous_lesson_id,
|
|
15
|
-
|
|
16
|
-
gf.epoch,
|
|
17
|
-
gf.google_drive_id,
|
|
18
|
-
gf.google_drive_url,
|
|
19
|
-
gf.opendocument_presentation_bucket_name,
|
|
20
|
-
gf.opendocument_presentation_bucket_path,
|
|
21
|
-
gf.opendocument_text_bucket_name,
|
|
22
|
-
gf.opendocument_text_bucket_path,
|
|
23
|
-
gf.pdf_bucket_name,
|
|
24
|
-
gf.pdf_bucket_path,
|
|
25
|
-
gf.powerpoint_bucket_name,
|
|
26
|
-
gf.powerpoint_bucket_path,
|
|
27
|
-
gf.word_bucket_name,
|
|
28
|
-
gf.word_bucket_path,
|
|
29
|
-
r.
|
|
30
|
-
r.
|
|
31
|
-
r.
|
|
32
|
-
r.
|
|
33
|
-
r.
|
|
34
|
-
r.
|
|
35
|
-
r.release_type AS r_release_type,
|
|
15
|
+
d.gdrive_file_id,
|
|
16
|
+
gf.epoch AS gdrive_files__epoch,
|
|
17
|
+
gf.google_drive_id AS gdrive_files__google_drive_id,
|
|
18
|
+
gf.google_drive_url AS gdrive_files__google_drive_url,
|
|
19
|
+
gf.opendocument_presentation_bucket_name AS gdrive_files__opendocument_presentation_bucket_name,
|
|
20
|
+
gf.opendocument_presentation_bucket_path AS gdrive_files__opendocument_presentation_bucket_path,
|
|
21
|
+
gf.opendocument_text_bucket_name AS gdrive_files__opendocument_text_bucket_name,
|
|
22
|
+
gf.opendocument_text_bucket_path AS gdrive_files__opendocument_text_bucket_path,
|
|
23
|
+
gf.pdf_bucket_name AS gdrive_files__pdf_bucket_name,
|
|
24
|
+
gf.pdf_bucket_path AS gdrive_files__pdf_bucket_path,
|
|
25
|
+
gf.powerpoint_bucket_name AS gdrive_files__powerpoint_bucket_name,
|
|
26
|
+
gf.powerpoint_bucket_path AS gdrive_files__powerpoint_bucket_path,
|
|
27
|
+
gf.word_bucket_name AS gdrive_files__word_bucket_name,
|
|
28
|
+
gf.word_bucket_path AS gdrive_files__word_bucket_path,
|
|
29
|
+
r.approved AS releases__approved,
|
|
30
|
+
r.description AS releases__description,
|
|
31
|
+
r.estimated_release_date AS releases__estimated_release_date,
|
|
32
|
+
r.name AS releases__name,
|
|
33
|
+
r.notes AS releases__notes,
|
|
34
|
+
r.release_type AS releases__release_type,
|
|
36
35
|
d._expire_on_release,
|
|
37
36
|
d._release_id,
|
|
38
37
|
d.created_at,
|
|
39
38
|
d.updated_at,
|
|
40
|
-
r.created_at
|
|
41
|
-
r.updated_at
|
|
39
|
+
r.created_at AS releases__created_at,
|
|
40
|
+
r.updated_at AS releases__updated_at
|
|
42
41
|
FROM raw.documents d
|
|
43
42
|
JOIN raw.gdrive_files gf ON gf.gdrive_file_id = d.gdrive_file_id
|
|
44
43
|
LEFT JOIN internal.releases r ON r.release_id = d._release_id
|
|
45
44
|
WHERE d._state = 'published'
|
|
46
|
-
`),
|
|
45
|
+
`),tn.view("sub_live_lesson_component_status",{lesson_component_id:ni("lesson_component_id"),lesson_component_type:yn("lesson_component_type"),operation_status:C_("operation_status"),active_media_id:ni("active_media_id"),active_media_type:vn("active_media_type"),last_ingest_id:gt("last_ingest_id"),created_at:ct("created_at",{withTimezone:!0})}).as(t.sql`
|
|
47
46
|
SELECT lesson_component_id,
|
|
48
47
|
lesson_component_type,
|
|
49
48
|
operation_status,
|
|
@@ -53,37 +52,36 @@
|
|
|
53
52
|
created_at
|
|
54
53
|
FROM internal.lesson_component_status
|
|
55
54
|
WHERE retired_at IS NULL
|
|
56
|
-
`),
|
|
55
|
+
`),tn.view("sub_draft_documents_with_status_by_lesson",{document_id:ni("document_id").notNull(),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}),lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),gdrive_file_id:ni("gdrive_file_id").notNull(),gdrive_files__epoch:nt("gdrive_files__epoch"),gdrive_files__google_drive_id:nt("gdrive_files__google_drive_id"),gdrive_files__google_drive_url:nt("gdrive_files__google_drive_url"),gdrive_files__opendocument_presentation_bucket_name:nt("gdrive_files__opendocument_presentation_bucket_name"),gdrive_files__opendocument_presentation_bucket_path:nt("gdrive_files__opendocument_presentation_bucket_path"),gdrive_files__opendocument_text_bucket_name:nt("gdrive_files__opendocument_text_bucket_name"),gdrive_files__opendocument_text_bucket_path:nt("gdrive_files__opendocument_text_bucket_path"),gdrive_files__pdf_bucket_name:nt("gdrive_files__pdf_bucket_name"),gdrive_files__pdf_bucket_path:nt("gdrive_files__pdf_bucket_path"),gdrive_files__powerpoint_bucket_name:nt("gdrive_files__powerpoint_bucket_name"),gdrive_files__powerpoint_bucket_path:nt("gdrive_files__powerpoint_bucket_path"),gdrive_files__word_bucket_name:nt("gdrive_files__word_bucket_name"),gdrive_files__word_bucket_path:nt("gdrive_files__word_bucket_path"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}),updated_at:ct("updated_at",{withTimezone:!0}),sub_live_lesson_component_status__operation_status:C_("sub_live_lesson_component_status__operation_status"),sub_live_lesson_component_status__active_media_id:ni("sub_live_lesson_component_status__active_media_id"),sub_live_lesson_component_status__active_media_type:vn("sub_live_lesson_component_status__active_media_type"),sub_live_lesson_component_status__last_ingest_id:gt("sub_live_lesson_component_status__last_ingest_id"),sub_live_lesson_component_status__created_at:ct("sub_live_lesson_component_status__created_at",{withTimezone:!0})}).as(t.sql`
|
|
57
56
|
SELECT
|
|
58
57
|
d.document_id,
|
|
59
|
-
d.deprecated_fields,
|
|
60
58
|
d.document_type,
|
|
61
59
|
d.document_uid,
|
|
62
60
|
d.lesson_id,
|
|
63
61
|
d.previous_lesson_id,
|
|
64
|
-
|
|
65
|
-
gf.epoch,
|
|
66
|
-
gf.google_drive_id,
|
|
67
|
-
gf.google_drive_url,
|
|
68
|
-
gf.opendocument_presentation_bucket_name,
|
|
69
|
-
gf.opendocument_presentation_bucket_path,
|
|
70
|
-
gf.opendocument_text_bucket_name,
|
|
71
|
-
gf.opendocument_text_bucket_path,
|
|
72
|
-
gf.pdf_bucket_name,
|
|
73
|
-
gf.pdf_bucket_path,
|
|
74
|
-
gf.powerpoint_bucket_name,
|
|
75
|
-
gf.powerpoint_bucket_path,
|
|
76
|
-
gf.word_bucket_name,
|
|
77
|
-
gf.word_bucket_path,
|
|
62
|
+
d.gdrive_file_id,
|
|
63
|
+
gf.epoch AS gdrive_files__epoch,
|
|
64
|
+
gf.google_drive_id AS gdrive_files__google_drive_id,
|
|
65
|
+
gf.google_drive_url AS gdrive_files__google_drive_url,
|
|
66
|
+
gf.opendocument_presentation_bucket_name AS gdrive_files__opendocument_presentation_bucket_name,
|
|
67
|
+
gf.opendocument_presentation_bucket_path AS gdrive_files__opendocument_presentation_bucket_path,
|
|
68
|
+
gf.opendocument_text_bucket_name AS gdrive_files__opendocument_text_bucket_name,
|
|
69
|
+
gf.opendocument_text_bucket_path AS gdrive_files__opendocument_text_bucket_path,
|
|
70
|
+
gf.pdf_bucket_name AS gdrive_files__pdf_bucket_name,
|
|
71
|
+
gf.pdf_bucket_path AS gdrive_files__pdf_bucket_path,
|
|
72
|
+
gf.powerpoint_bucket_name AS gdrive_files__powerpoint_bucket_name,
|
|
73
|
+
gf.powerpoint_bucket_path AS gdrive_files__powerpoint_bucket_path,
|
|
74
|
+
gf.word_bucket_name AS gdrive_files__word_bucket_name,
|
|
75
|
+
gf.word_bucket_path AS gdrive_files__word_bucket_path,
|
|
78
76
|
d._expire_on_release,
|
|
79
77
|
d._release_id,
|
|
80
78
|
d.created_at,
|
|
81
79
|
d.updated_at,
|
|
82
|
-
lcs.operation_status AS
|
|
83
|
-
lcs.active_media_id AS
|
|
84
|
-
lcs.active_media_type AS
|
|
85
|
-
lcs.last_ingest_id AS
|
|
86
|
-
lcs.created_at AS
|
|
80
|
+
lcs.operation_status AS sub_live_lesson_component_status__operation_status,
|
|
81
|
+
lcs.active_media_id AS sub_live_lesson_component_status__active_media_id,
|
|
82
|
+
lcs.active_media_type AS sub_live_lesson_component_status__active_media_type,
|
|
83
|
+
lcs.last_ingest_id AS sub_live_lesson_component_status__last_ingest_id,
|
|
84
|
+
lcs.created_at AS sub_live_lesson_component_status__created_at
|
|
87
85
|
FROM raw.documents d
|
|
88
86
|
LEFT JOIN raw.lessons l
|
|
89
87
|
ON l.lesson_id = d.lesson_id
|
|
@@ -93,15 +91,14 @@
|
|
|
93
91
|
ON lcs.lesson_component_id = d.document_id
|
|
94
92
|
AND lcs.lesson_component_type = 'document'
|
|
95
93
|
WHERE d._state = 'draft'
|
|
96
|
-
`);const
|
|
94
|
+
`);const D_=tn.view("draft_documents_with_status_by_lesson",{document_id:ni("document_id").notNull(),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}),lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),gdrive_file_id:ni("gdrive_file_id").notNull(),gdrive_files__epoch:nt("gdrive_files__epoch"),gdrive_files__google_drive_id:nt("gdrive_files__google_drive_id"),gdrive_files__google_drive_url:nt("gdrive_files__google_drive_url"),gdrive_files__opendocument_presentation_bucket_name:nt("gdrive_files__opendocument_presentation_bucket_name"),gdrive_files__opendocument_presentation_bucket_path:nt("gdrive_files__opendocument_presentation_bucket_path"),gdrive_files__opendocument_text_bucket_name:nt("gdrive_files__opendocument_text_bucket_name"),gdrive_files__opendocument_text_bucket_path:nt("gdrive_files__opendocument_text_bucket_path"),gdrive_files__pdf_bucket_name:nt("gdrive_files__pdf_bucket_name"),gdrive_files__pdf_bucket_path:nt("gdrive_files__pdf_bucket_path"),gdrive_files__powerpoint_bucket_name:nt("gdrive_files__powerpoint_bucket_name"),gdrive_files__powerpoint_bucket_path:nt("gdrive_files__powerpoint_bucket_path"),gdrive_files__word_bucket_name:nt("gdrive_files__word_bucket_name"),gdrive_files__word_bucket_path:nt("gdrive_files__word_bucket_path"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}),updated_at:ct("updated_at",{withTimezone:!0}),sub_live_lesson_component_status__operation_status:C_("sub_live_lesson_component_status__operation_status"),sub_live_lesson_component_status__active_media_id:ni("sub_live_lesson_component_status__active_media_id"),sub_live_lesson_component_status__active_media_type:vn("sub_live_lesson_component_status__active_media_type"),sub_live_lesson_component_status__last_ingest_id:gt("sub_live_lesson_component_status__last_ingest_id"),sub_live_lesson_component_status__created_at:ct("sub_live_lesson_component_status__created_at",{withTimezone:!0})}).as(t.sql`
|
|
97
95
|
SELECT *
|
|
98
96
|
FROM rendered.sub_draft_documents_with_status_by_lesson
|
|
99
|
-
`),
|
|
97
|
+
`),O_=tn.view("draft_lesson_with_status",{lesson_id:ni("lesson_id").notNull(),agf__has_copyright_restrictions:Be("agf__has_copyright_restrictions"),agf__restricted_download:Be("agf__restricted_download"),equipment_and_resources:mi("equipment_and_resources"),has_tag_practical_not_remote:Be("has_tag_practical_not_remote").notNull(),is_sensitive:Be("is_sensitive").notNull(),key_learning_points:mi("key_learning_points"),keywords:mi("keywords"),lesson_outline:mi("lesson_outline"),lesson_uid:Le("lesson_uid",{length:16}).notNull(),misconceptions_and_common_mistakes:mi("misconceptions_and_common_mistakes"),phonics_outcome:nt("phonics_outcome"),pupil_lesson_outcome:nt("pupil_lesson_outcome"),slug:nt("slug").notNull(),teacher_tips:mi("teacher_tips"),title:nt("title").notNull(),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}),updated_at:ct("updated_at",{withTimezone:!0}),lesson_status__status:T_("lesson_status__status"),lesson_status__approved:Be("lesson_status__approved"),lesson_status__last_approved:ct("lesson_status__last_approved"),lesson_status__last_error_location:nt("lesson_status__last_error_location"),lesson_status__last_error_message:nt("lesson_status__last_error_message"),lesson_status__last_error_timestamp:ct("lesson_status__last_error_timestamp"),lesson_status__created_at:ct("lesson_status__created_at",{withTimezone:!0}),lesson_status__updated_at:ct("lesson_status__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
100
98
|
SELECT
|
|
101
99
|
l.lesson_id,
|
|
102
100
|
l.agf__has_copyright_restrictions,
|
|
103
101
|
l.agf__restricted_download,
|
|
104
|
-
l.deprecated_fields,
|
|
105
102
|
l.equipment_and_resources,
|
|
106
103
|
l.has_tag_practical_not_remote,
|
|
107
104
|
l.is_sensitive,
|
|
@@ -119,23 +116,89 @@
|
|
|
119
116
|
l._release_id,
|
|
120
117
|
l.created_at,
|
|
121
118
|
l.updated_at,
|
|
122
|
-
ls.status AS
|
|
123
|
-
ls.approved AS
|
|
124
|
-
ls.last_approved AS
|
|
125
|
-
ls.last_error_location AS
|
|
126
|
-
ls.last_error_message AS
|
|
127
|
-
ls.last_error_timestamp AS
|
|
128
|
-
ls.created_at AS
|
|
129
|
-
ls.updated_at AS
|
|
119
|
+
ls.status AS lesson_status__status,
|
|
120
|
+
ls.approved AS lesson_status__approved,
|
|
121
|
+
ls.last_approved AS lesson_status__last_approved,
|
|
122
|
+
ls.last_error_location AS lesson_status__last_error_location,
|
|
123
|
+
ls.last_error_message AS lesson_status__last_error_message,
|
|
124
|
+
ls.last_error_timestamp AS lesson_status__last_error_timestamp,
|
|
125
|
+
ls.created_at AS lesson_status__created_at,
|
|
126
|
+
ls.updated_at AS lesson_status__updated_at
|
|
130
127
|
FROM raw.lessons l
|
|
131
128
|
LEFT JOIN internal.lesson_status ls ON ls.lesson_id = l.lesson_id
|
|
132
129
|
WHERE l._state = 'draft'
|
|
133
|
-
`)
|
|
130
|
+
`);tn.view("draft_lesson_video_with_status_by_lesson",{lesson_video_id:ni("lesson_video_id").notNull(),lesson_id:ni("lesson_id").notNull(),video_id:ni("video_id"),main_video___authoring_state:nn("main_video___authoring_state"),main_video__cloudinary_public_id:nt("main_video__cloudinary_public_id"),main_video__cloudinary_source_url:nt("main_video__cloudinary_source_url"),main_video__contains_identifiable_face:Be("main_video__contains_identifiable_face"),main_video__duration_seconds:$i("main_video__duration_seconds"),main_video__has_bsl:Be("main_video__has_bsl"),main_video__media_description:nt("main_video__media_description"),main_video__mux_asset_id:nt("main_video__mux_asset_id"),main_video__mux_playback_id:nt("main_video__mux_playback_id"),main_video__name:nt("main_video__name"),main_video__previous_lesson_video_id:ni("main_video__previous_lesson_video_id"),main_video__previous_media_clip_ids:ni("main_video__previous_media_clip_ids").array(),main_video__raw_mux_data:mi("main_video__raw_mux_data"),main_video__signed_stream_id:nt("main_video__signed_stream_id"),main_video__title:nt("main_video__title"),main_video__url:nt("main_video__url"),main_video__video_uid:Le("main_video__video_uid",{length:16}),main_video___expire_on_release:Be("main_video___expire_on_release"),main_video___release_id:ni("main_video___release_id"),main_video__created_at:ct("main_video__created_at",{withTimezone:!0}),main_video__updated_at:ct("main_video__updated_at",{withTimezone:!0}),sign_language_video_id:ni("sign_language_video_id"),sign_language_video___authoring_state:nn("sign_language_video___authoring_state"),sign_language_video__cloudinary_public_id:nt("sign_language_video__cloudinary_public_id"),sign_language_video__cloudinary_source_url:nt("sign_language_video__cloudinary_source_url"),sign_language_video__contains_identifiable_face:Be("sign_language_video__contains_identifiable_face"),sign_language_video__duration_seconds:$i("sign_language_video__duration_seconds"),sign_language_video__has_bsl:Be("sign_language_video__has_bsl"),sign_language_video__media_description:nt("sign_language_video__media_description"),sign_language_video__mux_asset_id:nt("sign_language_video__mux_asset_id"),sign_language_video__mux_playback_id:nt("sign_language_video__mux_playback_id"),sign_language_video__name:nt("sign_language_video__name"),sign_language_video__previous_lesson_video_id:ni("sign_language_video__previous_lesson_video_id"),sign_language_video__previous_media_clip_ids:ni("sign_language_video__previous_media_clip_ids").array(),sign_language_video__raw_mux_data:mi("sign_language_video__raw_mux_data"),sign_language_video__signed_stream_id:nt("sign_language_video__signed_stream_id"),sign_language_video__title:nt("sign_language_video__title"),sign_language_video__url:nt("sign_language_video__url"),sign_language_video__video_uid:Le("sign_language_video__video_uid",{length:16}),sign_language_video___expire_on_release:Be("sign_language_video___expire_on_release"),sign_language_video___release_id:ni("sign_language_video___release_id"),sign_language_video__created_at:ct("sign_language_video__created_at",{withTimezone:!0}),sign_language_video__updated_at:ct("sign_language_video__updated_at",{withTimezone:!0}),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}),updated_at:ct("updated_at",{withTimezone:!0}),sub_live_lesson_component_status__operation_status:C_("sub_live_lesson_component_status__operation_status"),sub_live_lesson_component_status__active_media_id:ni("sub_live_lesson_component_status__active_media_id"),sub_live_lesson_component_status__active_media_type:vn("sub_live_lesson_component_status__active_media_type"),sub_live_lesson_component_status__last_ingest_id:gt("sub_live_lesson_component_status__last_ingest_id"),sub_live_lesson_component_status__created_at:ct("sub_live_lesson_component_status__created_at",{withTimezone:!0})}).as(t.sql`
|
|
131
|
+
SELECT
|
|
132
|
+
lv.lesson_video_id,
|
|
133
|
+
lv.lesson_id,
|
|
134
|
+
lv.video_id,
|
|
135
|
+
v._authoring_state AS main_video___authoring_state,
|
|
136
|
+
v.cloudinary_public_id AS main_video__cloudinary_public_id,
|
|
137
|
+
v.cloudinary_source_url AS main_video__cloudinary_source_url,
|
|
138
|
+
v.contains_identifiable_face AS main_video__contains_identifiable_face,
|
|
139
|
+
v.duration_seconds AS main_video__duration_seconds,
|
|
140
|
+
v.has_bsl AS main_video__has_bsl,
|
|
141
|
+
v.media_description AS main_video__media_description,
|
|
142
|
+
v.mux_asset_id AS main_video__mux_asset_id,
|
|
143
|
+
v.mux_playback_id AS main_video__mux_playback_id,
|
|
144
|
+
v.name AS main_video__name,
|
|
145
|
+
v.previous_lesson_video_id AS main_video__previous_lesson_video_id,
|
|
146
|
+
v.previous_media_clip_ids AS main_video__previous_media_clip_ids,
|
|
147
|
+
v.raw_mux_data AS main_video__raw_mux_data,
|
|
148
|
+
v.signed_stream_id AS main_video__signed_stream_id,
|
|
149
|
+
v.title AS main_video__title,
|
|
150
|
+
v.url AS main_video__url,
|
|
151
|
+
v.video_uid AS main_video__video_uid,
|
|
152
|
+
v._expire_on_release AS main_video___expire_on_release,
|
|
153
|
+
v._release_id AS main_video___release_id,
|
|
154
|
+
v.created_at AS main_video__created_at,
|
|
155
|
+
v.updated_at AS main_video__updated_at,
|
|
156
|
+
lv.sign_language_video_id,
|
|
157
|
+
slv._authoring_state AS sign_language_video___authoring_state,
|
|
158
|
+
slv.cloudinary_public_id AS sign_language_video__cloudinary_public_id,
|
|
159
|
+
slv.cloudinary_source_url AS sign_language_video__cloudinary_source_url,
|
|
160
|
+
slv.contains_identifiable_face AS sign_language_video__contains_identifiable_face,
|
|
161
|
+
slv.duration_seconds AS sign_language_video__duration_seconds,
|
|
162
|
+
slv.has_bsl AS sign_language_video__has_bsl,
|
|
163
|
+
slv.media_description AS sign_language_video__media_description,
|
|
164
|
+
slv.mux_asset_id AS sign_language_video__mux_asset_id,
|
|
165
|
+
slv.mux_playback_id AS sign_language_video__mux_playback_id,
|
|
166
|
+
slv.name AS sign_language_video__name,
|
|
167
|
+
slv.previous_lesson_video_id AS sign_language_video__previous_lesson_video_id,
|
|
168
|
+
slv.previous_media_clip_ids AS sign_language_video__previous_media_clip_ids,
|
|
169
|
+
slv.raw_mux_data AS sign_language_video__raw_mux_data,
|
|
170
|
+
slv.signed_stream_id AS sign_language_video__signed_stream_id,
|
|
171
|
+
slv.title AS sign_language_video__title,
|
|
172
|
+
slv.url AS sign_language_video__url,
|
|
173
|
+
slv.video_uid AS sign_language_video__video_uid,
|
|
174
|
+
slv._expire_on_release AS sign_language_video___expire_on_release,
|
|
175
|
+
slv._release_id AS sign_language_video___release_id,
|
|
176
|
+
slv.created_at AS sign_language_video__created_at,
|
|
177
|
+
slv.updated_at AS sign_language_video__updated_at,
|
|
178
|
+
lv._expire_on_release,
|
|
179
|
+
lv._release_id,
|
|
180
|
+
lv.created_at,
|
|
181
|
+
lv.updated_at,
|
|
182
|
+
lcs.operation_status AS sub_live_lesson_component_status__operation_status,
|
|
183
|
+
lcs.active_media_id AS sub_live_lesson_component_status__active_media_id,
|
|
184
|
+
lcs.active_media_type AS sub_live_lesson_component_status__active_media_type,
|
|
185
|
+
lcs.last_ingest_id AS sub_live_lesson_component_status__last_ingest_id,
|
|
186
|
+
lcs.created_at AS sub_live_lesson_component_status__created_at
|
|
187
|
+
FROM raw.lesson_videos lv
|
|
188
|
+
JOIN raw.lessons l
|
|
189
|
+
ON l.lesson_id = lv.lesson_id
|
|
190
|
+
AND l._state = lv._state
|
|
191
|
+
LEFT JOIN raw.videos v ON v.video_id = lv.video_id
|
|
192
|
+
LEFT JOIN raw.videos slv ON slv.video_id = lv.sign_language_video_id
|
|
193
|
+
LEFT JOIN rendered.sub_live_lesson_component_status lcs
|
|
194
|
+
ON lcs.lesson_component_id = lv.lesson_video_id
|
|
195
|
+
AND lcs.lesson_component_type = 'lesson_video'
|
|
196
|
+
WHERE lv._state = 'draft'
|
|
197
|
+
`);const L_=tn.view("published_lesson_with_release",{lesson_id:ni("lesson_id").notNull(),agf__has_copyright_restrictions:Be("agf__has_copyright_restrictions"),agf__restricted_download:Be("agf__restricted_download"),equipment_and_resources:mi("equipment_and_resources"),has_tag_practical_not_remote:Be("has_tag_practical_not_remote").notNull(),is_sensitive:Be("is_sensitive").notNull(),key_learning_points:mi("key_learning_points").notNull(),keywords:mi("keywords"),lesson_outline:mi("lesson_outline"),lesson_uid:Le("lesson_uid",{length:16}).notNull(),misconceptions_and_common_mistakes:mi("misconceptions_and_common_mistakes"),phonics_outcome:nt("phonics_outcome"),pupil_lesson_outcome:nt("pupil_lesson_outcome").notNull(),slug:nt("slug").notNull(),teacher_tips:mi("teacher_tips"),title:nt("title").notNull(),releases__approved:Be("releases__approved"),releases__description:nt("releases__description"),releases__estimated_release_date:He("releases__estimated_release_date"),releases__name:nt("releases__name"),releases__notes:nt("releases__notes"),releases__release_type:Nn("releases__release_type"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}).notNull(),updated_at:ct("updated_at",{withTimezone:!0}).notNull(),releases__created_at:ct("releases__created_at",{withTimezone:!0}),releases__updated_at:ct("releases__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
134
198
|
SELECT
|
|
135
199
|
l.lesson_id,
|
|
136
200
|
l.agf__has_copyright_restrictions,
|
|
137
201
|
l.agf__restricted_download,
|
|
138
|
-
l.deprecated_fields,
|
|
139
202
|
l.equipment_and_resources,
|
|
140
203
|
l.has_tag_practical_not_remote,
|
|
141
204
|
l.is_sensitive,
|
|
@@ -149,91 +212,87 @@
|
|
|
149
212
|
l.slug,
|
|
150
213
|
l.teacher_tips,
|
|
151
214
|
l.title,
|
|
152
|
-
r.
|
|
153
|
-
r.
|
|
154
|
-
r.
|
|
155
|
-
r.
|
|
156
|
-
r.
|
|
157
|
-
r.
|
|
158
|
-
r.release_type AS r_release_type,
|
|
215
|
+
r.approved AS releases__approved,
|
|
216
|
+
r.description AS releases__description,
|
|
217
|
+
r.estimated_release_date AS releases__estimated_release_date,
|
|
218
|
+
r.name AS releases__name,
|
|
219
|
+
r.notes AS releases__notes,
|
|
220
|
+
r.release_type AS releases__release_type,
|
|
159
221
|
l._expire_on_release,
|
|
160
222
|
l._release_id,
|
|
161
223
|
l.created_at,
|
|
162
224
|
l.updated_at,
|
|
163
|
-
r.created_at AS
|
|
164
|
-
r.updated_at AS
|
|
225
|
+
r.created_at AS releases__created_at,
|
|
226
|
+
r.updated_at AS releases__updated_at
|
|
165
227
|
FROM raw.lessons l
|
|
166
228
|
LEFT JOIN internal.releases r ON r.release_id = l._release_id
|
|
167
229
|
WHERE l._state = 'published'
|
|
168
|
-
`),
|
|
230
|
+
`),I_=tn.view("published_documents_with_release_by_lesson",{document_id:ni("document_id").notNull(),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}).notNull(),lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),gdrive_file_id:ni("gdrive_file_id").notNull(),gdrive_files__epoch:nt("gdrive_files__epoch"),gdrive_files__google_drive_id:nt("gdrive_files__google_drive_id").notNull(),gdrive_files__google_drive_url:nt("gdrive_files__google_drive_url").notNull(),gdrive_files__opendocument_presentation_bucket_name:nt("gdrive_files__opendocument_presentation_bucket_name"),gdrive_files__opendocument_presentation_bucket_path:nt("gdrive_files__opendocument_presentation_bucket_path"),gdrive_files__opendocument_text_bucket_name:nt("gdrive_files__opendocument_text_bucket_name"),gdrive_files__opendocument_text_bucket_path:nt("gdrive_files__opendocument_text_bucket_path"),gdrive_files__pdf_bucket_name:nt("gdrive_files__pdf_bucket_name"),gdrive_files__pdf_bucket_path:nt("gdrive_files__pdf_bucket_path"),gdrive_files__powerpoint_bucket_name:nt("gdrive_files__powerpoint_bucket_name"),gdrive_files__powerpoint_bucket_path:nt("gdrive_files__powerpoint_bucket_path"),gdrive_files__word_bucket_name:nt("gdrive_files__word_bucket_name"),gdrive_files__word_bucket_path:nt("gdrive_files__word_bucket_path"),releases__approved:Be("releases__approved"),releases__description:nt("releases__description"),releases__estimated_release_date:He("releases__estimated_release_date"),releases__name:nt("releases__name"),releases__notes:nt("releases__notes"),releases__release_type:Nn("releases__release_type"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}).notNull(),updated_at:ct("updated_at",{withTimezone:!0}).notNull(),releases__created_at:ct("releases__created_at",{withTimezone:!0}),releases__updated_at:ct("releases__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
169
231
|
SELECT *
|
|
170
232
|
FROM rendered.sub_published_documents_with_release_by_lesson
|
|
171
|
-
`),
|
|
233
|
+
`),F_=tn.view("published_document_with_release_by_lesson_and_document_type",{document_id:ni("document_id").notNull(),document_type:Jn("document_type").notNull(),document_uid:Le("document_uid",{length:16}).notNull(),lesson_id:ni("lesson_id"),previous_lesson_id:ni("previous_lesson_id"),gdrive_file_id:ni("gdrive_file_id").notNull(),gdrive_files__epoch:nt("gdrive_files__epoch"),gdrive_files__google_drive_id:nt("gdrive_files__google_drive_id").notNull(),gdrive_files__google_drive_url:nt("gdrive_files__google_drive_url").notNull(),gdrive_files__opendocument_presentation_bucket_name:nt("gdrive_files__opendocument_presentation_bucket_name"),gdrive_files__opendocument_presentation_bucket_path:nt("gdrive_files__opendocument_presentation_bucket_path"),gdrive_files__opendocument_text_bucket_name:nt("gdrive_files__opendocument_text_bucket_name"),gdrive_files__opendocument_text_bucket_path:nt("gdrive_files__opendocument_text_bucket_path"),gdrive_files__pdf_bucket_name:nt("gdrive_files__pdf_bucket_name"),gdrive_files__pdf_bucket_path:nt("gdrive_files__pdf_bucket_path"),gdrive_files__powerpoint_bucket_name:nt("gdrive_files__powerpoint_bucket_name"),gdrive_files__powerpoint_bucket_path:nt("gdrive_files__powerpoint_bucket_path"),gdrive_files__word_bucket_name:nt("gdrive_files__word_bucket_name"),gdrive_files__word_bucket_path:nt("gdrive_files__word_bucket_path"),releases__approved:Be("releases__approved"),releases__description:nt("releases__description"),releases__estimated_release_date:He("releases__estimated_release_date"),releases__name:nt("releases__name"),releases__notes:nt("releases__notes"),releases__release_type:Nn("releases__release_type"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}).notNull(),updated_at:ct("updated_at",{withTimezone:!0}).notNull(),releases__created_at:ct("releases__created_at",{withTimezone:!0}),releases__updated_at:ct("releases__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
172
234
|
SELECT *
|
|
173
235
|
FROM rendered.sub_published_documents_with_release_by_lesson
|
|
174
|
-
`),
|
|
236
|
+
`),Q_=tn.view("published_lesson_video_with_release_by_lesson",{lesson_video_id:ni("lesson_video_id").notNull(),lesson_id:ni("lesson_id").notNull(),video_id:ni("video_id").notNull(),main_video___authoring_state:nn("main_video___authoring_state").notNull(),main_video__cloudinary_public_id:nt("main_video__cloudinary_public_id"),main_video__cloudinary_source_url:nt("main_video__cloudinary_source_url"),main_video__contains_identifiable_face:Be("main_video__contains_identifiable_face"),main_video__duration_seconds:$i("main_video__duration_seconds"),main_video__has_bsl:Be("main_video__has_bsl").notNull(),main_video__media_description:nt("main_video__media_description"),main_video__mux_asset_id:nt("main_video__mux_asset_id").notNull(),main_video__mux_playback_id:nt("main_video__mux_playback_id"),main_video__name:nt("main_video__name"),main_video__previous_lesson_video_id:ni("main_video__previous_lesson_video_id"),main_video__previous_media_clip_ids:ni("main_video__previous_media_clip_ids").array(),main_video__raw_mux_data:mi("main_video__raw_mux_data").notNull(),main_video__signed_stream_id:nt("main_video__signed_stream_id"),main_video__title:nt("main_video__title"),main_video__url:nt("main_video__url").notNull(),main_video__video_uid:Le("main_video__video_uid",{length:16}).notNull(),main_video___expire_on_release:Be("main_video___expire_on_release").notNull(),main_video___release_id:ni("main_video___release_id"),main_video__created_at:ct("main_video__created_at",{withTimezone:!0}).notNull(),main_video__updated_at:ct("main_video__updated_at",{withTimezone:!0}).notNull(),sign_language_video_id:ni("sign_language_video_id"),sign_language_video___authoring_state:nn("sign_language_video___authoring_state"),sign_language_video__cloudinary_public_id:nt("sign_language_video__cloudinary_public_id"),sign_language_video__cloudinary_source_url:nt("sign_language_video__cloudinary_source_url"),sign_language_video__contains_identifiable_face:Be("sign_language_video__contains_identifiable_face"),sign_language_video__duration_seconds:$i("sign_language_video__duration_seconds"),sign_language_video__has_bsl:Be("sign_language_video__has_bsl"),sign_language_video__media_description:nt("sign_language_video__media_description"),sign_language_video__mux_asset_id:nt("sign_language_video__mux_asset_id"),sign_language_video__mux_playback_id:nt("sign_language_video__mux_playback_id"),sign_language_video__name:nt("sign_language_video__name"),sign_language_video__previous_lesson_video_id:ni("sign_language_video__previous_lesson_video_id"),sign_language_video__previous_media_clip_ids:ni("sign_language_video__previous_media_clip_ids").array(),sign_language_video__raw_mux_data:mi("sign_language_video__raw_mux_data"),sign_language_video__signed_stream_id:nt("sign_language_video__signed_stream_id"),sign_language_video__title:nt("sign_language_video__title"),sign_language_video__url:nt("sign_language_video__url"),sign_language_video__video_uid:Le("sign_language_video__video_uid",{length:16}),sign_language_video___expire_on_release:Be("sign_language_video___expire_on_release"),sign_language_video___release_id:ni("sign_language_video___release_id"),sign_language_video__created_at:ct("sign_language_video__created_at",{withTimezone:!0}),sign_language_video__updated_at:ct("sign_language_video__updated_at",{withTimezone:!0}),releases__approved:Be("releases__approved"),releases__description:nt("releases__description"),releases__estimated_release_date:He("releases__estimated_release_date"),releases__name:nt("releases__name"),releases__notes:nt("releases__notes"),releases__release_type:Nn("releases__release_type"),_expire_on_release:Be("_expire_on_release").notNull(),_release_id:ni("_release_id"),created_at:ct("created_at",{withTimezone:!0}).notNull(),updated_at:ct("updated_at",{withTimezone:!0}).notNull(),releases__created_at:ct("releases__created_at",{withTimezone:!0}),releases__updated_at:ct("releases__updated_at",{withTimezone:!0})}).as(t.sql`
|
|
175
237
|
SELECT
|
|
176
238
|
lv.lesson_video_id,
|
|
177
239
|
lv.lesson_id,
|
|
178
|
-
|
|
179
|
-
v._authoring_state AS
|
|
180
|
-
v.cloudinary_public_id AS
|
|
181
|
-
v.cloudinary_source_url AS
|
|
182
|
-
v.contains_identifiable_face AS
|
|
183
|
-
v.
|
|
184
|
-
v.
|
|
185
|
-
v.
|
|
186
|
-
v.
|
|
187
|
-
v.
|
|
188
|
-
v.
|
|
189
|
-
v.
|
|
190
|
-
v.
|
|
191
|
-
v.
|
|
192
|
-
v.
|
|
193
|
-
v.
|
|
194
|
-
v.
|
|
195
|
-
v.
|
|
196
|
-
v.
|
|
197
|
-
v.
|
|
198
|
-
v.
|
|
199
|
-
v.
|
|
200
|
-
|
|
201
|
-
slv.
|
|
202
|
-
slv.
|
|
203
|
-
slv.
|
|
204
|
-
slv.
|
|
205
|
-
slv.
|
|
206
|
-
slv.
|
|
207
|
-
slv.
|
|
208
|
-
slv.
|
|
209
|
-
slv.
|
|
210
|
-
slv.
|
|
211
|
-
slv.
|
|
212
|
-
slv.
|
|
213
|
-
slv.
|
|
214
|
-
slv.
|
|
215
|
-
slv.
|
|
216
|
-
slv.
|
|
217
|
-
slv.
|
|
218
|
-
slv.
|
|
219
|
-
slv.
|
|
220
|
-
slv.
|
|
221
|
-
slv.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
r.
|
|
225
|
-
r.
|
|
226
|
-
r.
|
|
227
|
-
r.
|
|
228
|
-
r.name AS r_name,
|
|
229
|
-
r.notes AS r_notes,
|
|
230
|
-
r.release_type AS r_release_type,
|
|
240
|
+
lv.video_id,
|
|
241
|
+
v._authoring_state AS main_video___authoring_state,
|
|
242
|
+
v.cloudinary_public_id AS main_video__cloudinary_public_id,
|
|
243
|
+
v.cloudinary_source_url AS main_video__cloudinary_source_url,
|
|
244
|
+
v.contains_identifiable_face AS main_video__contains_identifiable_face,
|
|
245
|
+
v.duration_seconds AS main_video__duration_seconds,
|
|
246
|
+
v.has_bsl AS main_video__has_bsl,
|
|
247
|
+
v.media_description AS main_video__media_description,
|
|
248
|
+
v.mux_asset_id AS main_video__mux_asset_id,
|
|
249
|
+
v.mux_playback_id AS main_video__mux_playback_id,
|
|
250
|
+
v.name AS main_video__name,
|
|
251
|
+
v.previous_lesson_video_id AS main_video__previous_lesson_video_id,
|
|
252
|
+
v.previous_media_clip_ids AS main_video__previous_media_clip_ids,
|
|
253
|
+
v.raw_mux_data AS main_video__raw_mux_data,
|
|
254
|
+
v.signed_stream_id AS main_video__signed_stream_id,
|
|
255
|
+
v.title AS main_video__title,
|
|
256
|
+
v.url AS main_video__url,
|
|
257
|
+
v.video_uid AS main_video__video_uid,
|
|
258
|
+
v._expire_on_release AS main_video___expire_on_release,
|
|
259
|
+
v._release_id AS main_video___release_id,
|
|
260
|
+
v.created_at AS main_video__created_at,
|
|
261
|
+
v.updated_at AS main_video__updated_at,
|
|
262
|
+
lv.sign_language_video_id,
|
|
263
|
+
slv._authoring_state AS sign_language_video___authoring_state,
|
|
264
|
+
slv.cloudinary_public_id AS sign_language_video__cloudinary_public_id,
|
|
265
|
+
slv.cloudinary_source_url AS sign_language_video__cloudinary_source_url,
|
|
266
|
+
slv.contains_identifiable_face AS sign_language_video__contains_identifiable_face,
|
|
267
|
+
slv.duration_seconds AS sign_language_video__duration_seconds,
|
|
268
|
+
slv.has_bsl AS sign_language_video__has_bsl,
|
|
269
|
+
slv.media_description AS sign_language_video__media_description,
|
|
270
|
+
slv.mux_asset_id AS sign_language_video__mux_asset_id,
|
|
271
|
+
slv.mux_playback_id AS sign_language_video__mux_playback_id,
|
|
272
|
+
slv.name AS sign_language_video__name,
|
|
273
|
+
slv.previous_lesson_video_id AS sign_language_video__previous_lesson_video_id,
|
|
274
|
+
slv.previous_media_clip_ids AS sign_language_video__previous_media_clip_ids,
|
|
275
|
+
slv.raw_mux_data AS sign_language_video__raw_mux_data,
|
|
276
|
+
slv.signed_stream_id AS sign_language_video__signed_stream_id,
|
|
277
|
+
slv.title AS sign_language_video__title,
|
|
278
|
+
slv.url AS sign_language_video__url,
|
|
279
|
+
slv.video_uid AS sign_language_video__video_uid,
|
|
280
|
+
slv._expire_on_release AS sign_language_video___expire_on_release,
|
|
281
|
+
slv._release_id AS sign_language_video___release_id,
|
|
282
|
+
slv.created_at AS sign_language_video__created_at,
|
|
283
|
+
slv.updated_at AS sign_language_video__updated_at,
|
|
284
|
+
r.approved AS releases__approved,
|
|
285
|
+
r.description AS releases__description,
|
|
286
|
+
r.estimated_release_date AS releases__estimated_release_date,
|
|
287
|
+
r.name AS releases__name,
|
|
288
|
+
r.notes AS releases__notes,
|
|
289
|
+
r.release_type AS releases__release_type,
|
|
231
290
|
lv._expire_on_release,
|
|
232
291
|
lv._release_id,
|
|
233
292
|
lv.created_at,
|
|
234
293
|
lv.updated_at,
|
|
235
|
-
r.created_at AS
|
|
236
|
-
r.updated_at AS
|
|
294
|
+
r.created_at AS releases__created_at,
|
|
295
|
+
r.updated_at AS releases__updated_at
|
|
237
296
|
FROM raw.lesson_videos lv
|
|
238
297
|
JOIN raw.lessons l
|
|
239
298
|
ON l.lesson_id = lv.lesson_id
|
|
@@ -242,50 +301,50 @@
|
|
|
242
301
|
LEFT JOIN raw.videos slv ON slv.video_id = lv.sign_language_video_id
|
|
243
302
|
LEFT JOIN internal.releases r ON r.release_id = lv._release_id
|
|
244
303
|
WHERE lv._state = 'published'
|
|
245
|
-
`),
|
|
304
|
+
`),E_=tn.view("unit_contexts_by_unit",{subject_id:ni("subject_id").notNull(),year_id:ni("year_id").notNull(),unit_id:ni("unit_id").notNull(),_state:nn("_state").notNull(),subjects__subject:nt("subjects__subject"),subjects__subject_parent_id:ni("subjects__subject_parent_id"),subjects__non_curriculum:Be("subjects__non_curriculum"),subjects__description:nt("subjects__description"),subjects__global_position:ni("subjects__global_position").notNull(),subjects__slug:nt("subjects__slug"),years__year:nt("years__year"),years__key_stage_id:ni("years__key_stage_id").notNull(),years__phase_id:ni("years__phase_id").notNull(),years__description:nt("years__description"),years__global_position:ni("years__global_position").notNull(),years__slug:nt("years__slug"),key_stages__key_stage:nt("key_stages__key_stage"),key_stages__description:nt("key_stages__description"),key_stages__global_position:ni("key_stages__global_position").notNull(),key_stages__slug:nt("key_stages__slug"),phases__phase:nt("phases__phase"),phases__description:nt("phases__description"),phases__global_position:ni("phases__global_position").notNull(),phases__slug:nt("phases__slug")}).as(t.sql`
|
|
246
305
|
SELECT
|
|
247
306
|
uc.subject_id,
|
|
248
307
|
uc.year_id,
|
|
249
308
|
uc.unit_id,
|
|
250
309
|
uc._state,
|
|
251
|
-
s.subject,
|
|
252
|
-
s.subject_parent_id,
|
|
253
|
-
s.non_curriculum,
|
|
254
|
-
s.description
|
|
255
|
-
s.global_position AS
|
|
256
|
-
s.slug
|
|
257
|
-
y.year,
|
|
258
|
-
y.key_stage_id,
|
|
259
|
-
y.phase_id,
|
|
260
|
-
y.description
|
|
261
|
-
y.global_position AS
|
|
262
|
-
y.slug
|
|
263
|
-
ks.key_stage,
|
|
264
|
-
ks.description
|
|
265
|
-
ks.global_position AS
|
|
266
|
-
ks.slug
|
|
267
|
-
p.phase,
|
|
268
|
-
p.description
|
|
269
|
-
p.global_position AS
|
|
270
|
-
p.slug
|
|
310
|
+
s.subject AS subjects__subject,
|
|
311
|
+
s.subject_parent_id AS subjects__subject_parent_id,
|
|
312
|
+
s.non_curriculum AS subjects__non_curriculum,
|
|
313
|
+
s.description AS subjects__description,
|
|
314
|
+
s.global_position AS subjects__global_position,
|
|
315
|
+
s.slug AS subjects__slug,
|
|
316
|
+
y.year AS years__year,
|
|
317
|
+
y.key_stage_id AS years__key_stage_id,
|
|
318
|
+
y.phase_id AS years__phase_id,
|
|
319
|
+
y.description AS years__description,
|
|
320
|
+
y.global_position AS years__global_position,
|
|
321
|
+
y.slug AS years__slug,
|
|
322
|
+
ks.key_stage AS key_stages__key_stage,
|
|
323
|
+
ks.description AS key_stages__description,
|
|
324
|
+
ks.global_position AS key_stages__global_position,
|
|
325
|
+
ks.slug AS key_stages__slug,
|
|
326
|
+
p.phase AS phases__phase,
|
|
327
|
+
p.description AS phases__description,
|
|
328
|
+
p.global_position AS phases__global_position,
|
|
329
|
+
p.slug AS phases__slug
|
|
271
330
|
FROM raw.unit_catalogue uc
|
|
272
331
|
JOIN raw.subjects s ON s.subject_id = uc.subject_id
|
|
273
332
|
JOIN raw.years y ON y.year_id = uc.year_id
|
|
274
333
|
JOIN raw.key_stages ks ON ks.key_stage_id = y.key_stage_id
|
|
275
334
|
JOIN raw.phases p ON p.phase_id = y.phase_id
|
|
276
|
-
`),
|
|
335
|
+
`),V_=tn.view("units_by_lesson",{lesson_id:ni("lesson_id").notNull(),_lesson_state:nn("_lesson_state").notNull(),unit_id:ni("unit_id").notNull(),_unit_state:nn("_unit_state").notNull(),position:ni("position").notNull(),units__title:nt("units__title").notNull(),units__slug:nt("units__slug"),units__description:nt("units__description").notNull()}).as(t.sql`
|
|
277
336
|
SELECT
|
|
278
337
|
ul.lesson_id,
|
|
279
338
|
ul._lesson_state,
|
|
280
339
|
ul.unit_id,
|
|
281
340
|
ul._unit_state,
|
|
282
341
|
ul.position,
|
|
283
|
-
u.title,
|
|
284
|
-
u.slug,
|
|
285
|
-
u.description
|
|
342
|
+
u.title AS units__title,
|
|
343
|
+
u.slug AS units__slug,
|
|
344
|
+
u.description AS units__description
|
|
286
345
|
FROM raw.unit_lessons ul
|
|
287
346
|
JOIN raw.units u
|
|
288
347
|
ON u.unit_id = ul.unit_id
|
|
289
348
|
AND u._state = ul._unit_state
|
|
290
|
-
`),
|
|
349
|
+
`),K_=s.z.object({equipment:s.z.string()}),U_=s.z.object({key_learning_point:s.z.string()}),J_=s.z.object({keyword:s.z.string(),description:s.z.string()}),R_=s.z.object({lesson_outline:s.z.string()}),M_=s.z.object({misconception:s.z.string(),response:s.z.string()}),W_=s.z.object({teacher_tip:s.z.string()}),H_=i.createSelectSchema(O_,{equipment_and_resources:s.z.array(K_).nullable(),key_learning_points:s.z.array(U_).nullable(),keywords:s.z.array(J_).nullable(),lesson_outline:s.z.array(R_).nullable(),misconceptions_and_common_mistakes:s.z.array(M_).nullable(),teacher_tips:s.z.array(W_).nullable()}),G_=_.default(H_),Y_=i.createSelectSchema(L_,{equipment_and_resources:s.z.array(K_).nullable(),key_learning_points:s.z.array(U_),keywords:s.z.array(J_).nullable(),lesson_outline:s.z.array(R_).nullable(),misconceptions_and_common_mistakes:s.z.array(M_).nullable(),teacher_tips:s.z.array(W_).nullable()}),Z_=_.default(Y_),X_=i.createSelectSchema(D_),ea=_.default(X_),ia=i.createSelectSchema(F_),ta=_.default(ia),sa=i.createSelectSchema(I_),na=_.default(sa),_a=s.z.record(s.z.string(),s.z.unknown()),aa=i.createSelectSchema(Q_,{main_video__raw_mux_data:_a,sign_language_video__raw_mux_data:_a.nullable()}),oa=_.default(aa),ra=i.createSelectSchema(E_),la=_.default(ra),da=i.createSelectSchema(V_),ua=_.default(da);exports.draftDocumentsWithStatusByLessonCamelSchema=ea,exports.draftDocumentsWithStatusByLessonSchema=X_,exports.draftLessonWithStatusCamelSchema=G_,exports.draftLessonWithStatusSchema=H_,exports.publishedDocumentWithReleaseByLessonAndDocumentTypeCamelSchema=ta,exports.publishedDocumentWithReleaseByLessonAndDocumentTypeSchema=ia,exports.publishedDocumentsWithReleaseByLessonCamelSchema=na,exports.publishedDocumentsWithReleaseByLessonSchema=sa,exports.publishedLessonVideoWithReleaseByLessonCamelSchema=oa,exports.publishedLessonVideoWithReleaseByLessonSchema=aa,exports.publishedLessonWithReleaseCamelSchema=Z_,exports.publishedLessonWithReleaseSchema=Y_,exports.unitContextsByUnitCamelSchema=la,exports.unitContextsByUnitSchema=ra,exports.unitsByLessonCamelSchema=ua,exports.unitsByLessonSchema=da;
|
|
291
350
|
//# sourceMappingURL=index.cjs.map
|