mutation.go 192 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "sync"
  7. "time"
  8. "github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
  9. "github.com/crowdsecurity/crowdsec/pkg/database/ent/bouncer"
  10. "github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
  11. "github.com/crowdsecurity/crowdsec/pkg/database/ent/event"
  12. "github.com/crowdsecurity/crowdsec/pkg/database/ent/machine"
  13. "github.com/crowdsecurity/crowdsec/pkg/database/ent/meta"
  14. "github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
  15. "entgo.io/ent"
  16. )
  17. const (
  18. // Operation types.
  19. OpCreate = ent.OpCreate
  20. OpDelete = ent.OpDelete
  21. OpDeleteOne = ent.OpDeleteOne
  22. OpUpdate = ent.OpUpdate
  23. OpUpdateOne = ent.OpUpdateOne
  24. // Node types.
  25. TypeAlert = "Alert"
  26. TypeBouncer = "Bouncer"
  27. TypeDecision = "Decision"
  28. TypeEvent = "Event"
  29. TypeMachine = "Machine"
  30. TypeMeta = "Meta"
  31. )
  32. // AlertMutation represents an operation that mutates the Alert nodes in the graph.
  33. type AlertMutation struct {
  34. config
  35. op Op
  36. typ string
  37. id *int
  38. created_at *time.Time
  39. updated_at *time.Time
  40. scenario *string
  41. bucketId *string
  42. message *string
  43. eventsCount *int32
  44. addeventsCount *int32
  45. startedAt *time.Time
  46. stoppedAt *time.Time
  47. sourceIp *string
  48. sourceRange *string
  49. sourceAsNumber *string
  50. sourceAsName *string
  51. sourceCountry *string
  52. sourceLatitude *float32
  53. addsourceLatitude *float32
  54. sourceLongitude *float32
  55. addsourceLongitude *float32
  56. sourceScope *string
  57. sourceValue *string
  58. capacity *int32
  59. addcapacity *int32
  60. leakSpeed *string
  61. scenarioVersion *string
  62. scenarioHash *string
  63. simulated *bool
  64. clearedFields map[string]struct{}
  65. owner *int
  66. clearedowner bool
  67. decisions map[int]struct{}
  68. removeddecisions map[int]struct{}
  69. cleareddecisions bool
  70. events map[int]struct{}
  71. removedevents map[int]struct{}
  72. clearedevents bool
  73. metas map[int]struct{}
  74. removedmetas map[int]struct{}
  75. clearedmetas bool
  76. done bool
  77. oldValue func(context.Context) (*Alert, error)
  78. predicates []predicate.Alert
  79. }
  80. var _ ent.Mutation = (*AlertMutation)(nil)
  81. // alertOption allows management of the mutation configuration using functional options.
  82. type alertOption func(*AlertMutation)
  83. // newAlertMutation creates new mutation for the Alert entity.
  84. func newAlertMutation(c config, op Op, opts ...alertOption) *AlertMutation {
  85. m := &AlertMutation{
  86. config: c,
  87. op: op,
  88. typ: TypeAlert,
  89. clearedFields: make(map[string]struct{}),
  90. }
  91. for _, opt := range opts {
  92. opt(m)
  93. }
  94. return m
  95. }
  96. // withAlertID sets the ID field of the mutation.
  97. func withAlertID(id int) alertOption {
  98. return func(m *AlertMutation) {
  99. var (
  100. err error
  101. once sync.Once
  102. value *Alert
  103. )
  104. m.oldValue = func(ctx context.Context) (*Alert, error) {
  105. once.Do(func() {
  106. if m.done {
  107. err = fmt.Errorf("querying old values post mutation is not allowed")
  108. } else {
  109. value, err = m.Client().Alert.Get(ctx, id)
  110. }
  111. })
  112. return value, err
  113. }
  114. m.id = &id
  115. }
  116. }
  117. // withAlert sets the old Alert of the mutation.
  118. func withAlert(node *Alert) alertOption {
  119. return func(m *AlertMutation) {
  120. m.oldValue = func(context.Context) (*Alert, error) {
  121. return node, nil
  122. }
  123. m.id = &node.ID
  124. }
  125. }
  126. // Client returns a new `ent.Client` from the mutation. If the mutation was
  127. // executed in a transaction (ent.Tx), a transactional client is returned.
  128. func (m AlertMutation) Client() *Client {
  129. client := &Client{config: m.config}
  130. client.init()
  131. return client
  132. }
  133. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  134. // it returns an error otherwise.
  135. func (m AlertMutation) Tx() (*Tx, error) {
  136. if _, ok := m.driver.(*txDriver); !ok {
  137. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  138. }
  139. tx := &Tx{config: m.config}
  140. tx.init()
  141. return tx, nil
  142. }
  143. // ID returns the ID value in the mutation. Note that the ID is only available
  144. // if it was provided to the builder or after it was returned from the database.
  145. func (m *AlertMutation) ID() (id int, exists bool) {
  146. if m.id == nil {
  147. return
  148. }
  149. return *m.id, true
  150. }
  151. // SetCreatedAt sets the "created_at" field.
  152. func (m *AlertMutation) SetCreatedAt(t time.Time) {
  153. m.created_at = &t
  154. }
  155. // CreatedAt returns the value of the "created_at" field in the mutation.
  156. func (m *AlertMutation) CreatedAt() (r time.Time, exists bool) {
  157. v := m.created_at
  158. if v == nil {
  159. return
  160. }
  161. return *v, true
  162. }
  163. // OldCreatedAt returns the old "created_at" field's value of the Alert entity.
  164. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  165. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  166. func (m *AlertMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  167. if !m.op.Is(OpUpdateOne) {
  168. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  169. }
  170. if m.id == nil || m.oldValue == nil {
  171. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  172. }
  173. oldValue, err := m.oldValue(ctx)
  174. if err != nil {
  175. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  176. }
  177. return oldValue.CreatedAt, nil
  178. }
  179. // ClearCreatedAt clears the value of the "created_at" field.
  180. func (m *AlertMutation) ClearCreatedAt() {
  181. m.created_at = nil
  182. m.clearedFields[alert.FieldCreatedAt] = struct{}{}
  183. }
  184. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  185. func (m *AlertMutation) CreatedAtCleared() bool {
  186. _, ok := m.clearedFields[alert.FieldCreatedAt]
  187. return ok
  188. }
  189. // ResetCreatedAt resets all changes to the "created_at" field.
  190. func (m *AlertMutation) ResetCreatedAt() {
  191. m.created_at = nil
  192. delete(m.clearedFields, alert.FieldCreatedAt)
  193. }
  194. // SetUpdatedAt sets the "updated_at" field.
  195. func (m *AlertMutation) SetUpdatedAt(t time.Time) {
  196. m.updated_at = &t
  197. }
  198. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  199. func (m *AlertMutation) UpdatedAt() (r time.Time, exists bool) {
  200. v := m.updated_at
  201. if v == nil {
  202. return
  203. }
  204. return *v, true
  205. }
  206. // OldUpdatedAt returns the old "updated_at" field's value of the Alert entity.
  207. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  208. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  209. func (m *AlertMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  210. if !m.op.Is(OpUpdateOne) {
  211. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  212. }
  213. if m.id == nil || m.oldValue == nil {
  214. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  215. }
  216. oldValue, err := m.oldValue(ctx)
  217. if err != nil {
  218. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  219. }
  220. return oldValue.UpdatedAt, nil
  221. }
  222. // ClearUpdatedAt clears the value of the "updated_at" field.
  223. func (m *AlertMutation) ClearUpdatedAt() {
  224. m.updated_at = nil
  225. m.clearedFields[alert.FieldUpdatedAt] = struct{}{}
  226. }
  227. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  228. func (m *AlertMutation) UpdatedAtCleared() bool {
  229. _, ok := m.clearedFields[alert.FieldUpdatedAt]
  230. return ok
  231. }
  232. // ResetUpdatedAt resets all changes to the "updated_at" field.
  233. func (m *AlertMutation) ResetUpdatedAt() {
  234. m.updated_at = nil
  235. delete(m.clearedFields, alert.FieldUpdatedAt)
  236. }
  237. // SetScenario sets the "scenario" field.
  238. func (m *AlertMutation) SetScenario(s string) {
  239. m.scenario = &s
  240. }
  241. // Scenario returns the value of the "scenario" field in the mutation.
  242. func (m *AlertMutation) Scenario() (r string, exists bool) {
  243. v := m.scenario
  244. if v == nil {
  245. return
  246. }
  247. return *v, true
  248. }
  249. // OldScenario returns the old "scenario" field's value of the Alert entity.
  250. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  251. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  252. func (m *AlertMutation) OldScenario(ctx context.Context) (v string, err error) {
  253. if !m.op.Is(OpUpdateOne) {
  254. return v, fmt.Errorf("OldScenario is only allowed on UpdateOne operations")
  255. }
  256. if m.id == nil || m.oldValue == nil {
  257. return v, fmt.Errorf("OldScenario requires an ID field in the mutation")
  258. }
  259. oldValue, err := m.oldValue(ctx)
  260. if err != nil {
  261. return v, fmt.Errorf("querying old value for OldScenario: %w", err)
  262. }
  263. return oldValue.Scenario, nil
  264. }
  265. // ResetScenario resets all changes to the "scenario" field.
  266. func (m *AlertMutation) ResetScenario() {
  267. m.scenario = nil
  268. }
  269. // SetBucketId sets the "bucketId" field.
  270. func (m *AlertMutation) SetBucketId(s string) {
  271. m.bucketId = &s
  272. }
  273. // BucketId returns the value of the "bucketId" field in the mutation.
  274. func (m *AlertMutation) BucketId() (r string, exists bool) {
  275. v := m.bucketId
  276. if v == nil {
  277. return
  278. }
  279. return *v, true
  280. }
  281. // OldBucketId returns the old "bucketId" field's value of the Alert entity.
  282. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  283. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  284. func (m *AlertMutation) OldBucketId(ctx context.Context) (v string, err error) {
  285. if !m.op.Is(OpUpdateOne) {
  286. return v, fmt.Errorf("OldBucketId is only allowed on UpdateOne operations")
  287. }
  288. if m.id == nil || m.oldValue == nil {
  289. return v, fmt.Errorf("OldBucketId requires an ID field in the mutation")
  290. }
  291. oldValue, err := m.oldValue(ctx)
  292. if err != nil {
  293. return v, fmt.Errorf("querying old value for OldBucketId: %w", err)
  294. }
  295. return oldValue.BucketId, nil
  296. }
  297. // ClearBucketId clears the value of the "bucketId" field.
  298. func (m *AlertMutation) ClearBucketId() {
  299. m.bucketId = nil
  300. m.clearedFields[alert.FieldBucketId] = struct{}{}
  301. }
  302. // BucketIdCleared returns if the "bucketId" field was cleared in this mutation.
  303. func (m *AlertMutation) BucketIdCleared() bool {
  304. _, ok := m.clearedFields[alert.FieldBucketId]
  305. return ok
  306. }
  307. // ResetBucketId resets all changes to the "bucketId" field.
  308. func (m *AlertMutation) ResetBucketId() {
  309. m.bucketId = nil
  310. delete(m.clearedFields, alert.FieldBucketId)
  311. }
  312. // SetMessage sets the "message" field.
  313. func (m *AlertMutation) SetMessage(s string) {
  314. m.message = &s
  315. }
  316. // Message returns the value of the "message" field in the mutation.
  317. func (m *AlertMutation) Message() (r string, exists bool) {
  318. v := m.message
  319. if v == nil {
  320. return
  321. }
  322. return *v, true
  323. }
  324. // OldMessage returns the old "message" field's value of the Alert entity.
  325. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  326. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  327. func (m *AlertMutation) OldMessage(ctx context.Context) (v string, err error) {
  328. if !m.op.Is(OpUpdateOne) {
  329. return v, fmt.Errorf("OldMessage is only allowed on UpdateOne operations")
  330. }
  331. if m.id == nil || m.oldValue == nil {
  332. return v, fmt.Errorf("OldMessage requires an ID field in the mutation")
  333. }
  334. oldValue, err := m.oldValue(ctx)
  335. if err != nil {
  336. return v, fmt.Errorf("querying old value for OldMessage: %w", err)
  337. }
  338. return oldValue.Message, nil
  339. }
  340. // ClearMessage clears the value of the "message" field.
  341. func (m *AlertMutation) ClearMessage() {
  342. m.message = nil
  343. m.clearedFields[alert.FieldMessage] = struct{}{}
  344. }
  345. // MessageCleared returns if the "message" field was cleared in this mutation.
  346. func (m *AlertMutation) MessageCleared() bool {
  347. _, ok := m.clearedFields[alert.FieldMessage]
  348. return ok
  349. }
  350. // ResetMessage resets all changes to the "message" field.
  351. func (m *AlertMutation) ResetMessage() {
  352. m.message = nil
  353. delete(m.clearedFields, alert.FieldMessage)
  354. }
  355. // SetEventsCount sets the "eventsCount" field.
  356. func (m *AlertMutation) SetEventsCount(i int32) {
  357. m.eventsCount = &i
  358. m.addeventsCount = nil
  359. }
  360. // EventsCount returns the value of the "eventsCount" field in the mutation.
  361. func (m *AlertMutation) EventsCount() (r int32, exists bool) {
  362. v := m.eventsCount
  363. if v == nil {
  364. return
  365. }
  366. return *v, true
  367. }
  368. // OldEventsCount returns the old "eventsCount" field's value of the Alert entity.
  369. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  370. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  371. func (m *AlertMutation) OldEventsCount(ctx context.Context) (v int32, err error) {
  372. if !m.op.Is(OpUpdateOne) {
  373. return v, fmt.Errorf("OldEventsCount is only allowed on UpdateOne operations")
  374. }
  375. if m.id == nil || m.oldValue == nil {
  376. return v, fmt.Errorf("OldEventsCount requires an ID field in the mutation")
  377. }
  378. oldValue, err := m.oldValue(ctx)
  379. if err != nil {
  380. return v, fmt.Errorf("querying old value for OldEventsCount: %w", err)
  381. }
  382. return oldValue.EventsCount, nil
  383. }
  384. // AddEventsCount adds i to the "eventsCount" field.
  385. func (m *AlertMutation) AddEventsCount(i int32) {
  386. if m.addeventsCount != nil {
  387. *m.addeventsCount += i
  388. } else {
  389. m.addeventsCount = &i
  390. }
  391. }
  392. // AddedEventsCount returns the value that was added to the "eventsCount" field in this mutation.
  393. func (m *AlertMutation) AddedEventsCount() (r int32, exists bool) {
  394. v := m.addeventsCount
  395. if v == nil {
  396. return
  397. }
  398. return *v, true
  399. }
  400. // ClearEventsCount clears the value of the "eventsCount" field.
  401. func (m *AlertMutation) ClearEventsCount() {
  402. m.eventsCount = nil
  403. m.addeventsCount = nil
  404. m.clearedFields[alert.FieldEventsCount] = struct{}{}
  405. }
  406. // EventsCountCleared returns if the "eventsCount" field was cleared in this mutation.
  407. func (m *AlertMutation) EventsCountCleared() bool {
  408. _, ok := m.clearedFields[alert.FieldEventsCount]
  409. return ok
  410. }
  411. // ResetEventsCount resets all changes to the "eventsCount" field.
  412. func (m *AlertMutation) ResetEventsCount() {
  413. m.eventsCount = nil
  414. m.addeventsCount = nil
  415. delete(m.clearedFields, alert.FieldEventsCount)
  416. }
  417. // SetStartedAt sets the "startedAt" field.
  418. func (m *AlertMutation) SetStartedAt(t time.Time) {
  419. m.startedAt = &t
  420. }
  421. // StartedAt returns the value of the "startedAt" field in the mutation.
  422. func (m *AlertMutation) StartedAt() (r time.Time, exists bool) {
  423. v := m.startedAt
  424. if v == nil {
  425. return
  426. }
  427. return *v, true
  428. }
  429. // OldStartedAt returns the old "startedAt" field's value of the Alert entity.
  430. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  431. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  432. func (m *AlertMutation) OldStartedAt(ctx context.Context) (v time.Time, err error) {
  433. if !m.op.Is(OpUpdateOne) {
  434. return v, fmt.Errorf("OldStartedAt is only allowed on UpdateOne operations")
  435. }
  436. if m.id == nil || m.oldValue == nil {
  437. return v, fmt.Errorf("OldStartedAt requires an ID field in the mutation")
  438. }
  439. oldValue, err := m.oldValue(ctx)
  440. if err != nil {
  441. return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
  442. }
  443. return oldValue.StartedAt, nil
  444. }
  445. // ClearStartedAt clears the value of the "startedAt" field.
  446. func (m *AlertMutation) ClearStartedAt() {
  447. m.startedAt = nil
  448. m.clearedFields[alert.FieldStartedAt] = struct{}{}
  449. }
  450. // StartedAtCleared returns if the "startedAt" field was cleared in this mutation.
  451. func (m *AlertMutation) StartedAtCleared() bool {
  452. _, ok := m.clearedFields[alert.FieldStartedAt]
  453. return ok
  454. }
  455. // ResetStartedAt resets all changes to the "startedAt" field.
  456. func (m *AlertMutation) ResetStartedAt() {
  457. m.startedAt = nil
  458. delete(m.clearedFields, alert.FieldStartedAt)
  459. }
  460. // SetStoppedAt sets the "stoppedAt" field.
  461. func (m *AlertMutation) SetStoppedAt(t time.Time) {
  462. m.stoppedAt = &t
  463. }
  464. // StoppedAt returns the value of the "stoppedAt" field in the mutation.
  465. func (m *AlertMutation) StoppedAt() (r time.Time, exists bool) {
  466. v := m.stoppedAt
  467. if v == nil {
  468. return
  469. }
  470. return *v, true
  471. }
  472. // OldStoppedAt returns the old "stoppedAt" field's value of the Alert entity.
  473. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  474. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  475. func (m *AlertMutation) OldStoppedAt(ctx context.Context) (v time.Time, err error) {
  476. if !m.op.Is(OpUpdateOne) {
  477. return v, fmt.Errorf("OldStoppedAt is only allowed on UpdateOne operations")
  478. }
  479. if m.id == nil || m.oldValue == nil {
  480. return v, fmt.Errorf("OldStoppedAt requires an ID field in the mutation")
  481. }
  482. oldValue, err := m.oldValue(ctx)
  483. if err != nil {
  484. return v, fmt.Errorf("querying old value for OldStoppedAt: %w", err)
  485. }
  486. return oldValue.StoppedAt, nil
  487. }
  488. // ClearStoppedAt clears the value of the "stoppedAt" field.
  489. func (m *AlertMutation) ClearStoppedAt() {
  490. m.stoppedAt = nil
  491. m.clearedFields[alert.FieldStoppedAt] = struct{}{}
  492. }
  493. // StoppedAtCleared returns if the "stoppedAt" field was cleared in this mutation.
  494. func (m *AlertMutation) StoppedAtCleared() bool {
  495. _, ok := m.clearedFields[alert.FieldStoppedAt]
  496. return ok
  497. }
  498. // ResetStoppedAt resets all changes to the "stoppedAt" field.
  499. func (m *AlertMutation) ResetStoppedAt() {
  500. m.stoppedAt = nil
  501. delete(m.clearedFields, alert.FieldStoppedAt)
  502. }
  503. // SetSourceIp sets the "sourceIp" field.
  504. func (m *AlertMutation) SetSourceIp(s string) {
  505. m.sourceIp = &s
  506. }
  507. // SourceIp returns the value of the "sourceIp" field in the mutation.
  508. func (m *AlertMutation) SourceIp() (r string, exists bool) {
  509. v := m.sourceIp
  510. if v == nil {
  511. return
  512. }
  513. return *v, true
  514. }
  515. // OldSourceIp returns the old "sourceIp" field's value of the Alert entity.
  516. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  517. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  518. func (m *AlertMutation) OldSourceIp(ctx context.Context) (v string, err error) {
  519. if !m.op.Is(OpUpdateOne) {
  520. return v, fmt.Errorf("OldSourceIp is only allowed on UpdateOne operations")
  521. }
  522. if m.id == nil || m.oldValue == nil {
  523. return v, fmt.Errorf("OldSourceIp requires an ID field in the mutation")
  524. }
  525. oldValue, err := m.oldValue(ctx)
  526. if err != nil {
  527. return v, fmt.Errorf("querying old value for OldSourceIp: %w", err)
  528. }
  529. return oldValue.SourceIp, nil
  530. }
  531. // ClearSourceIp clears the value of the "sourceIp" field.
  532. func (m *AlertMutation) ClearSourceIp() {
  533. m.sourceIp = nil
  534. m.clearedFields[alert.FieldSourceIp] = struct{}{}
  535. }
  536. // SourceIpCleared returns if the "sourceIp" field was cleared in this mutation.
  537. func (m *AlertMutation) SourceIpCleared() bool {
  538. _, ok := m.clearedFields[alert.FieldSourceIp]
  539. return ok
  540. }
  541. // ResetSourceIp resets all changes to the "sourceIp" field.
  542. func (m *AlertMutation) ResetSourceIp() {
  543. m.sourceIp = nil
  544. delete(m.clearedFields, alert.FieldSourceIp)
  545. }
  546. // SetSourceRange sets the "sourceRange" field.
  547. func (m *AlertMutation) SetSourceRange(s string) {
  548. m.sourceRange = &s
  549. }
  550. // SourceRange returns the value of the "sourceRange" field in the mutation.
  551. func (m *AlertMutation) SourceRange() (r string, exists bool) {
  552. v := m.sourceRange
  553. if v == nil {
  554. return
  555. }
  556. return *v, true
  557. }
  558. // OldSourceRange returns the old "sourceRange" field's value of the Alert entity.
  559. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  560. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  561. func (m *AlertMutation) OldSourceRange(ctx context.Context) (v string, err error) {
  562. if !m.op.Is(OpUpdateOne) {
  563. return v, fmt.Errorf("OldSourceRange is only allowed on UpdateOne operations")
  564. }
  565. if m.id == nil || m.oldValue == nil {
  566. return v, fmt.Errorf("OldSourceRange requires an ID field in the mutation")
  567. }
  568. oldValue, err := m.oldValue(ctx)
  569. if err != nil {
  570. return v, fmt.Errorf("querying old value for OldSourceRange: %w", err)
  571. }
  572. return oldValue.SourceRange, nil
  573. }
  574. // ClearSourceRange clears the value of the "sourceRange" field.
  575. func (m *AlertMutation) ClearSourceRange() {
  576. m.sourceRange = nil
  577. m.clearedFields[alert.FieldSourceRange] = struct{}{}
  578. }
  579. // SourceRangeCleared returns if the "sourceRange" field was cleared in this mutation.
  580. func (m *AlertMutation) SourceRangeCleared() bool {
  581. _, ok := m.clearedFields[alert.FieldSourceRange]
  582. return ok
  583. }
  584. // ResetSourceRange resets all changes to the "sourceRange" field.
  585. func (m *AlertMutation) ResetSourceRange() {
  586. m.sourceRange = nil
  587. delete(m.clearedFields, alert.FieldSourceRange)
  588. }
  589. // SetSourceAsNumber sets the "sourceAsNumber" field.
  590. func (m *AlertMutation) SetSourceAsNumber(s string) {
  591. m.sourceAsNumber = &s
  592. }
  593. // SourceAsNumber returns the value of the "sourceAsNumber" field in the mutation.
  594. func (m *AlertMutation) SourceAsNumber() (r string, exists bool) {
  595. v := m.sourceAsNumber
  596. if v == nil {
  597. return
  598. }
  599. return *v, true
  600. }
  601. // OldSourceAsNumber returns the old "sourceAsNumber" field's value of the Alert entity.
  602. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  603. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  604. func (m *AlertMutation) OldSourceAsNumber(ctx context.Context) (v string, err error) {
  605. if !m.op.Is(OpUpdateOne) {
  606. return v, fmt.Errorf("OldSourceAsNumber is only allowed on UpdateOne operations")
  607. }
  608. if m.id == nil || m.oldValue == nil {
  609. return v, fmt.Errorf("OldSourceAsNumber requires an ID field in the mutation")
  610. }
  611. oldValue, err := m.oldValue(ctx)
  612. if err != nil {
  613. return v, fmt.Errorf("querying old value for OldSourceAsNumber: %w", err)
  614. }
  615. return oldValue.SourceAsNumber, nil
  616. }
  617. // ClearSourceAsNumber clears the value of the "sourceAsNumber" field.
  618. func (m *AlertMutation) ClearSourceAsNumber() {
  619. m.sourceAsNumber = nil
  620. m.clearedFields[alert.FieldSourceAsNumber] = struct{}{}
  621. }
  622. // SourceAsNumberCleared returns if the "sourceAsNumber" field was cleared in this mutation.
  623. func (m *AlertMutation) SourceAsNumberCleared() bool {
  624. _, ok := m.clearedFields[alert.FieldSourceAsNumber]
  625. return ok
  626. }
  627. // ResetSourceAsNumber resets all changes to the "sourceAsNumber" field.
  628. func (m *AlertMutation) ResetSourceAsNumber() {
  629. m.sourceAsNumber = nil
  630. delete(m.clearedFields, alert.FieldSourceAsNumber)
  631. }
  632. // SetSourceAsName sets the "sourceAsName" field.
  633. func (m *AlertMutation) SetSourceAsName(s string) {
  634. m.sourceAsName = &s
  635. }
  636. // SourceAsName returns the value of the "sourceAsName" field in the mutation.
  637. func (m *AlertMutation) SourceAsName() (r string, exists bool) {
  638. v := m.sourceAsName
  639. if v == nil {
  640. return
  641. }
  642. return *v, true
  643. }
  644. // OldSourceAsName returns the old "sourceAsName" field's value of the Alert entity.
  645. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  646. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  647. func (m *AlertMutation) OldSourceAsName(ctx context.Context) (v string, err error) {
  648. if !m.op.Is(OpUpdateOne) {
  649. return v, fmt.Errorf("OldSourceAsName is only allowed on UpdateOne operations")
  650. }
  651. if m.id == nil || m.oldValue == nil {
  652. return v, fmt.Errorf("OldSourceAsName requires an ID field in the mutation")
  653. }
  654. oldValue, err := m.oldValue(ctx)
  655. if err != nil {
  656. return v, fmt.Errorf("querying old value for OldSourceAsName: %w", err)
  657. }
  658. return oldValue.SourceAsName, nil
  659. }
  660. // ClearSourceAsName clears the value of the "sourceAsName" field.
  661. func (m *AlertMutation) ClearSourceAsName() {
  662. m.sourceAsName = nil
  663. m.clearedFields[alert.FieldSourceAsName] = struct{}{}
  664. }
  665. // SourceAsNameCleared returns if the "sourceAsName" field was cleared in this mutation.
  666. func (m *AlertMutation) SourceAsNameCleared() bool {
  667. _, ok := m.clearedFields[alert.FieldSourceAsName]
  668. return ok
  669. }
  670. // ResetSourceAsName resets all changes to the "sourceAsName" field.
  671. func (m *AlertMutation) ResetSourceAsName() {
  672. m.sourceAsName = nil
  673. delete(m.clearedFields, alert.FieldSourceAsName)
  674. }
  675. // SetSourceCountry sets the "sourceCountry" field.
  676. func (m *AlertMutation) SetSourceCountry(s string) {
  677. m.sourceCountry = &s
  678. }
  679. // SourceCountry returns the value of the "sourceCountry" field in the mutation.
  680. func (m *AlertMutation) SourceCountry() (r string, exists bool) {
  681. v := m.sourceCountry
  682. if v == nil {
  683. return
  684. }
  685. return *v, true
  686. }
  687. // OldSourceCountry returns the old "sourceCountry" field's value of the Alert entity.
  688. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  689. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  690. func (m *AlertMutation) OldSourceCountry(ctx context.Context) (v string, err error) {
  691. if !m.op.Is(OpUpdateOne) {
  692. return v, fmt.Errorf("OldSourceCountry is only allowed on UpdateOne operations")
  693. }
  694. if m.id == nil || m.oldValue == nil {
  695. return v, fmt.Errorf("OldSourceCountry requires an ID field in the mutation")
  696. }
  697. oldValue, err := m.oldValue(ctx)
  698. if err != nil {
  699. return v, fmt.Errorf("querying old value for OldSourceCountry: %w", err)
  700. }
  701. return oldValue.SourceCountry, nil
  702. }
  703. // ClearSourceCountry clears the value of the "sourceCountry" field.
  704. func (m *AlertMutation) ClearSourceCountry() {
  705. m.sourceCountry = nil
  706. m.clearedFields[alert.FieldSourceCountry] = struct{}{}
  707. }
  708. // SourceCountryCleared returns if the "sourceCountry" field was cleared in this mutation.
  709. func (m *AlertMutation) SourceCountryCleared() bool {
  710. _, ok := m.clearedFields[alert.FieldSourceCountry]
  711. return ok
  712. }
  713. // ResetSourceCountry resets all changes to the "sourceCountry" field.
  714. func (m *AlertMutation) ResetSourceCountry() {
  715. m.sourceCountry = nil
  716. delete(m.clearedFields, alert.FieldSourceCountry)
  717. }
  718. // SetSourceLatitude sets the "sourceLatitude" field.
  719. func (m *AlertMutation) SetSourceLatitude(f float32) {
  720. m.sourceLatitude = &f
  721. m.addsourceLatitude = nil
  722. }
  723. // SourceLatitude returns the value of the "sourceLatitude" field in the mutation.
  724. func (m *AlertMutation) SourceLatitude() (r float32, exists bool) {
  725. v := m.sourceLatitude
  726. if v == nil {
  727. return
  728. }
  729. return *v, true
  730. }
  731. // OldSourceLatitude returns the old "sourceLatitude" field's value of the Alert entity.
  732. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  733. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  734. func (m *AlertMutation) OldSourceLatitude(ctx context.Context) (v float32, err error) {
  735. if !m.op.Is(OpUpdateOne) {
  736. return v, fmt.Errorf("OldSourceLatitude is only allowed on UpdateOne operations")
  737. }
  738. if m.id == nil || m.oldValue == nil {
  739. return v, fmt.Errorf("OldSourceLatitude requires an ID field in the mutation")
  740. }
  741. oldValue, err := m.oldValue(ctx)
  742. if err != nil {
  743. return v, fmt.Errorf("querying old value for OldSourceLatitude: %w", err)
  744. }
  745. return oldValue.SourceLatitude, nil
  746. }
  747. // AddSourceLatitude adds f to the "sourceLatitude" field.
  748. func (m *AlertMutation) AddSourceLatitude(f float32) {
  749. if m.addsourceLatitude != nil {
  750. *m.addsourceLatitude += f
  751. } else {
  752. m.addsourceLatitude = &f
  753. }
  754. }
  755. // AddedSourceLatitude returns the value that was added to the "sourceLatitude" field in this mutation.
  756. func (m *AlertMutation) AddedSourceLatitude() (r float32, exists bool) {
  757. v := m.addsourceLatitude
  758. if v == nil {
  759. return
  760. }
  761. return *v, true
  762. }
  763. // ClearSourceLatitude clears the value of the "sourceLatitude" field.
  764. func (m *AlertMutation) ClearSourceLatitude() {
  765. m.sourceLatitude = nil
  766. m.addsourceLatitude = nil
  767. m.clearedFields[alert.FieldSourceLatitude] = struct{}{}
  768. }
  769. // SourceLatitudeCleared returns if the "sourceLatitude" field was cleared in this mutation.
  770. func (m *AlertMutation) SourceLatitudeCleared() bool {
  771. _, ok := m.clearedFields[alert.FieldSourceLatitude]
  772. return ok
  773. }
  774. // ResetSourceLatitude resets all changes to the "sourceLatitude" field.
  775. func (m *AlertMutation) ResetSourceLatitude() {
  776. m.sourceLatitude = nil
  777. m.addsourceLatitude = nil
  778. delete(m.clearedFields, alert.FieldSourceLatitude)
  779. }
  780. // SetSourceLongitude sets the "sourceLongitude" field.
  781. func (m *AlertMutation) SetSourceLongitude(f float32) {
  782. m.sourceLongitude = &f
  783. m.addsourceLongitude = nil
  784. }
  785. // SourceLongitude returns the value of the "sourceLongitude" field in the mutation.
  786. func (m *AlertMutation) SourceLongitude() (r float32, exists bool) {
  787. v := m.sourceLongitude
  788. if v == nil {
  789. return
  790. }
  791. return *v, true
  792. }
  793. // OldSourceLongitude returns the old "sourceLongitude" field's value of the Alert entity.
  794. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  795. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  796. func (m *AlertMutation) OldSourceLongitude(ctx context.Context) (v float32, err error) {
  797. if !m.op.Is(OpUpdateOne) {
  798. return v, fmt.Errorf("OldSourceLongitude is only allowed on UpdateOne operations")
  799. }
  800. if m.id == nil || m.oldValue == nil {
  801. return v, fmt.Errorf("OldSourceLongitude requires an ID field in the mutation")
  802. }
  803. oldValue, err := m.oldValue(ctx)
  804. if err != nil {
  805. return v, fmt.Errorf("querying old value for OldSourceLongitude: %w", err)
  806. }
  807. return oldValue.SourceLongitude, nil
  808. }
  809. // AddSourceLongitude adds f to the "sourceLongitude" field.
  810. func (m *AlertMutation) AddSourceLongitude(f float32) {
  811. if m.addsourceLongitude != nil {
  812. *m.addsourceLongitude += f
  813. } else {
  814. m.addsourceLongitude = &f
  815. }
  816. }
  817. // AddedSourceLongitude returns the value that was added to the "sourceLongitude" field in this mutation.
  818. func (m *AlertMutation) AddedSourceLongitude() (r float32, exists bool) {
  819. v := m.addsourceLongitude
  820. if v == nil {
  821. return
  822. }
  823. return *v, true
  824. }
  825. // ClearSourceLongitude clears the value of the "sourceLongitude" field.
  826. func (m *AlertMutation) ClearSourceLongitude() {
  827. m.sourceLongitude = nil
  828. m.addsourceLongitude = nil
  829. m.clearedFields[alert.FieldSourceLongitude] = struct{}{}
  830. }
  831. // SourceLongitudeCleared returns if the "sourceLongitude" field was cleared in this mutation.
  832. func (m *AlertMutation) SourceLongitudeCleared() bool {
  833. _, ok := m.clearedFields[alert.FieldSourceLongitude]
  834. return ok
  835. }
  836. // ResetSourceLongitude resets all changes to the "sourceLongitude" field.
  837. func (m *AlertMutation) ResetSourceLongitude() {
  838. m.sourceLongitude = nil
  839. m.addsourceLongitude = nil
  840. delete(m.clearedFields, alert.FieldSourceLongitude)
  841. }
  842. // SetSourceScope sets the "sourceScope" field.
  843. func (m *AlertMutation) SetSourceScope(s string) {
  844. m.sourceScope = &s
  845. }
  846. // SourceScope returns the value of the "sourceScope" field in the mutation.
  847. func (m *AlertMutation) SourceScope() (r string, exists bool) {
  848. v := m.sourceScope
  849. if v == nil {
  850. return
  851. }
  852. return *v, true
  853. }
  854. // OldSourceScope returns the old "sourceScope" field's value of the Alert entity.
  855. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  856. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  857. func (m *AlertMutation) OldSourceScope(ctx context.Context) (v string, err error) {
  858. if !m.op.Is(OpUpdateOne) {
  859. return v, fmt.Errorf("OldSourceScope is only allowed on UpdateOne operations")
  860. }
  861. if m.id == nil || m.oldValue == nil {
  862. return v, fmt.Errorf("OldSourceScope requires an ID field in the mutation")
  863. }
  864. oldValue, err := m.oldValue(ctx)
  865. if err != nil {
  866. return v, fmt.Errorf("querying old value for OldSourceScope: %w", err)
  867. }
  868. return oldValue.SourceScope, nil
  869. }
  870. // ClearSourceScope clears the value of the "sourceScope" field.
  871. func (m *AlertMutation) ClearSourceScope() {
  872. m.sourceScope = nil
  873. m.clearedFields[alert.FieldSourceScope] = struct{}{}
  874. }
  875. // SourceScopeCleared returns if the "sourceScope" field was cleared in this mutation.
  876. func (m *AlertMutation) SourceScopeCleared() bool {
  877. _, ok := m.clearedFields[alert.FieldSourceScope]
  878. return ok
  879. }
  880. // ResetSourceScope resets all changes to the "sourceScope" field.
  881. func (m *AlertMutation) ResetSourceScope() {
  882. m.sourceScope = nil
  883. delete(m.clearedFields, alert.FieldSourceScope)
  884. }
  885. // SetSourceValue sets the "sourceValue" field.
  886. func (m *AlertMutation) SetSourceValue(s string) {
  887. m.sourceValue = &s
  888. }
  889. // SourceValue returns the value of the "sourceValue" field in the mutation.
  890. func (m *AlertMutation) SourceValue() (r string, exists bool) {
  891. v := m.sourceValue
  892. if v == nil {
  893. return
  894. }
  895. return *v, true
  896. }
  897. // OldSourceValue returns the old "sourceValue" field's value of the Alert entity.
  898. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  899. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  900. func (m *AlertMutation) OldSourceValue(ctx context.Context) (v string, err error) {
  901. if !m.op.Is(OpUpdateOne) {
  902. return v, fmt.Errorf("OldSourceValue is only allowed on UpdateOne operations")
  903. }
  904. if m.id == nil || m.oldValue == nil {
  905. return v, fmt.Errorf("OldSourceValue requires an ID field in the mutation")
  906. }
  907. oldValue, err := m.oldValue(ctx)
  908. if err != nil {
  909. return v, fmt.Errorf("querying old value for OldSourceValue: %w", err)
  910. }
  911. return oldValue.SourceValue, nil
  912. }
  913. // ClearSourceValue clears the value of the "sourceValue" field.
  914. func (m *AlertMutation) ClearSourceValue() {
  915. m.sourceValue = nil
  916. m.clearedFields[alert.FieldSourceValue] = struct{}{}
  917. }
  918. // SourceValueCleared returns if the "sourceValue" field was cleared in this mutation.
  919. func (m *AlertMutation) SourceValueCleared() bool {
  920. _, ok := m.clearedFields[alert.FieldSourceValue]
  921. return ok
  922. }
  923. // ResetSourceValue resets all changes to the "sourceValue" field.
  924. func (m *AlertMutation) ResetSourceValue() {
  925. m.sourceValue = nil
  926. delete(m.clearedFields, alert.FieldSourceValue)
  927. }
  928. // SetCapacity sets the "capacity" field.
  929. func (m *AlertMutation) SetCapacity(i int32) {
  930. m.capacity = &i
  931. m.addcapacity = nil
  932. }
  933. // Capacity returns the value of the "capacity" field in the mutation.
  934. func (m *AlertMutation) Capacity() (r int32, exists bool) {
  935. v := m.capacity
  936. if v == nil {
  937. return
  938. }
  939. return *v, true
  940. }
  941. // OldCapacity returns the old "capacity" field's value of the Alert entity.
  942. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  943. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  944. func (m *AlertMutation) OldCapacity(ctx context.Context) (v int32, err error) {
  945. if !m.op.Is(OpUpdateOne) {
  946. return v, fmt.Errorf("OldCapacity is only allowed on UpdateOne operations")
  947. }
  948. if m.id == nil || m.oldValue == nil {
  949. return v, fmt.Errorf("OldCapacity requires an ID field in the mutation")
  950. }
  951. oldValue, err := m.oldValue(ctx)
  952. if err != nil {
  953. return v, fmt.Errorf("querying old value for OldCapacity: %w", err)
  954. }
  955. return oldValue.Capacity, nil
  956. }
  957. // AddCapacity adds i to the "capacity" field.
  958. func (m *AlertMutation) AddCapacity(i int32) {
  959. if m.addcapacity != nil {
  960. *m.addcapacity += i
  961. } else {
  962. m.addcapacity = &i
  963. }
  964. }
  965. // AddedCapacity returns the value that was added to the "capacity" field in this mutation.
  966. func (m *AlertMutation) AddedCapacity() (r int32, exists bool) {
  967. v := m.addcapacity
  968. if v == nil {
  969. return
  970. }
  971. return *v, true
  972. }
  973. // ClearCapacity clears the value of the "capacity" field.
  974. func (m *AlertMutation) ClearCapacity() {
  975. m.capacity = nil
  976. m.addcapacity = nil
  977. m.clearedFields[alert.FieldCapacity] = struct{}{}
  978. }
  979. // CapacityCleared returns if the "capacity" field was cleared in this mutation.
  980. func (m *AlertMutation) CapacityCleared() bool {
  981. _, ok := m.clearedFields[alert.FieldCapacity]
  982. return ok
  983. }
  984. // ResetCapacity resets all changes to the "capacity" field.
  985. func (m *AlertMutation) ResetCapacity() {
  986. m.capacity = nil
  987. m.addcapacity = nil
  988. delete(m.clearedFields, alert.FieldCapacity)
  989. }
  990. // SetLeakSpeed sets the "leakSpeed" field.
  991. func (m *AlertMutation) SetLeakSpeed(s string) {
  992. m.leakSpeed = &s
  993. }
  994. // LeakSpeed returns the value of the "leakSpeed" field in the mutation.
  995. func (m *AlertMutation) LeakSpeed() (r string, exists bool) {
  996. v := m.leakSpeed
  997. if v == nil {
  998. return
  999. }
  1000. return *v, true
  1001. }
  1002. // OldLeakSpeed returns the old "leakSpeed" field's value of the Alert entity.
  1003. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  1004. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1005. func (m *AlertMutation) OldLeakSpeed(ctx context.Context) (v string, err error) {
  1006. if !m.op.Is(OpUpdateOne) {
  1007. return v, fmt.Errorf("OldLeakSpeed is only allowed on UpdateOne operations")
  1008. }
  1009. if m.id == nil || m.oldValue == nil {
  1010. return v, fmt.Errorf("OldLeakSpeed requires an ID field in the mutation")
  1011. }
  1012. oldValue, err := m.oldValue(ctx)
  1013. if err != nil {
  1014. return v, fmt.Errorf("querying old value for OldLeakSpeed: %w", err)
  1015. }
  1016. return oldValue.LeakSpeed, nil
  1017. }
  1018. // ClearLeakSpeed clears the value of the "leakSpeed" field.
  1019. func (m *AlertMutation) ClearLeakSpeed() {
  1020. m.leakSpeed = nil
  1021. m.clearedFields[alert.FieldLeakSpeed] = struct{}{}
  1022. }
  1023. // LeakSpeedCleared returns if the "leakSpeed" field was cleared in this mutation.
  1024. func (m *AlertMutation) LeakSpeedCleared() bool {
  1025. _, ok := m.clearedFields[alert.FieldLeakSpeed]
  1026. return ok
  1027. }
  1028. // ResetLeakSpeed resets all changes to the "leakSpeed" field.
  1029. func (m *AlertMutation) ResetLeakSpeed() {
  1030. m.leakSpeed = nil
  1031. delete(m.clearedFields, alert.FieldLeakSpeed)
  1032. }
  1033. // SetScenarioVersion sets the "scenarioVersion" field.
  1034. func (m *AlertMutation) SetScenarioVersion(s string) {
  1035. m.scenarioVersion = &s
  1036. }
  1037. // ScenarioVersion returns the value of the "scenarioVersion" field in the mutation.
  1038. func (m *AlertMutation) ScenarioVersion() (r string, exists bool) {
  1039. v := m.scenarioVersion
  1040. if v == nil {
  1041. return
  1042. }
  1043. return *v, true
  1044. }
  1045. // OldScenarioVersion returns the old "scenarioVersion" field's value of the Alert entity.
  1046. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  1047. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1048. func (m *AlertMutation) OldScenarioVersion(ctx context.Context) (v string, err error) {
  1049. if !m.op.Is(OpUpdateOne) {
  1050. return v, fmt.Errorf("OldScenarioVersion is only allowed on UpdateOne operations")
  1051. }
  1052. if m.id == nil || m.oldValue == nil {
  1053. return v, fmt.Errorf("OldScenarioVersion requires an ID field in the mutation")
  1054. }
  1055. oldValue, err := m.oldValue(ctx)
  1056. if err != nil {
  1057. return v, fmt.Errorf("querying old value for OldScenarioVersion: %w", err)
  1058. }
  1059. return oldValue.ScenarioVersion, nil
  1060. }
  1061. // ClearScenarioVersion clears the value of the "scenarioVersion" field.
  1062. func (m *AlertMutation) ClearScenarioVersion() {
  1063. m.scenarioVersion = nil
  1064. m.clearedFields[alert.FieldScenarioVersion] = struct{}{}
  1065. }
  1066. // ScenarioVersionCleared returns if the "scenarioVersion" field was cleared in this mutation.
  1067. func (m *AlertMutation) ScenarioVersionCleared() bool {
  1068. _, ok := m.clearedFields[alert.FieldScenarioVersion]
  1069. return ok
  1070. }
  1071. // ResetScenarioVersion resets all changes to the "scenarioVersion" field.
  1072. func (m *AlertMutation) ResetScenarioVersion() {
  1073. m.scenarioVersion = nil
  1074. delete(m.clearedFields, alert.FieldScenarioVersion)
  1075. }
  1076. // SetScenarioHash sets the "scenarioHash" field.
  1077. func (m *AlertMutation) SetScenarioHash(s string) {
  1078. m.scenarioHash = &s
  1079. }
  1080. // ScenarioHash returns the value of the "scenarioHash" field in the mutation.
  1081. func (m *AlertMutation) ScenarioHash() (r string, exists bool) {
  1082. v := m.scenarioHash
  1083. if v == nil {
  1084. return
  1085. }
  1086. return *v, true
  1087. }
  1088. // OldScenarioHash returns the old "scenarioHash" field's value of the Alert entity.
  1089. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  1090. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1091. func (m *AlertMutation) OldScenarioHash(ctx context.Context) (v string, err error) {
  1092. if !m.op.Is(OpUpdateOne) {
  1093. return v, fmt.Errorf("OldScenarioHash is only allowed on UpdateOne operations")
  1094. }
  1095. if m.id == nil || m.oldValue == nil {
  1096. return v, fmt.Errorf("OldScenarioHash requires an ID field in the mutation")
  1097. }
  1098. oldValue, err := m.oldValue(ctx)
  1099. if err != nil {
  1100. return v, fmt.Errorf("querying old value for OldScenarioHash: %w", err)
  1101. }
  1102. return oldValue.ScenarioHash, nil
  1103. }
  1104. // ClearScenarioHash clears the value of the "scenarioHash" field.
  1105. func (m *AlertMutation) ClearScenarioHash() {
  1106. m.scenarioHash = nil
  1107. m.clearedFields[alert.FieldScenarioHash] = struct{}{}
  1108. }
  1109. // ScenarioHashCleared returns if the "scenarioHash" field was cleared in this mutation.
  1110. func (m *AlertMutation) ScenarioHashCleared() bool {
  1111. _, ok := m.clearedFields[alert.FieldScenarioHash]
  1112. return ok
  1113. }
  1114. // ResetScenarioHash resets all changes to the "scenarioHash" field.
  1115. func (m *AlertMutation) ResetScenarioHash() {
  1116. m.scenarioHash = nil
  1117. delete(m.clearedFields, alert.FieldScenarioHash)
  1118. }
  1119. // SetSimulated sets the "simulated" field.
  1120. func (m *AlertMutation) SetSimulated(b bool) {
  1121. m.simulated = &b
  1122. }
  1123. // Simulated returns the value of the "simulated" field in the mutation.
  1124. func (m *AlertMutation) Simulated() (r bool, exists bool) {
  1125. v := m.simulated
  1126. if v == nil {
  1127. return
  1128. }
  1129. return *v, true
  1130. }
  1131. // OldSimulated returns the old "simulated" field's value of the Alert entity.
  1132. // If the Alert object wasn't provided to the builder, the object is fetched from the database.
  1133. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1134. func (m *AlertMutation) OldSimulated(ctx context.Context) (v bool, err error) {
  1135. if !m.op.Is(OpUpdateOne) {
  1136. return v, fmt.Errorf("OldSimulated is only allowed on UpdateOne operations")
  1137. }
  1138. if m.id == nil || m.oldValue == nil {
  1139. return v, fmt.Errorf("OldSimulated requires an ID field in the mutation")
  1140. }
  1141. oldValue, err := m.oldValue(ctx)
  1142. if err != nil {
  1143. return v, fmt.Errorf("querying old value for OldSimulated: %w", err)
  1144. }
  1145. return oldValue.Simulated, nil
  1146. }
  1147. // ResetSimulated resets all changes to the "simulated" field.
  1148. func (m *AlertMutation) ResetSimulated() {
  1149. m.simulated = nil
  1150. }
  1151. // SetOwnerID sets the "owner" edge to the Machine entity by id.
  1152. func (m *AlertMutation) SetOwnerID(id int) {
  1153. m.owner = &id
  1154. }
  1155. // ClearOwner clears the "owner" edge to the Machine entity.
  1156. func (m *AlertMutation) ClearOwner() {
  1157. m.clearedowner = true
  1158. }
  1159. // OwnerCleared reports if the "owner" edge to the Machine entity was cleared.
  1160. func (m *AlertMutation) OwnerCleared() bool {
  1161. return m.clearedowner
  1162. }
  1163. // OwnerID returns the "owner" edge ID in the mutation.
  1164. func (m *AlertMutation) OwnerID() (id int, exists bool) {
  1165. if m.owner != nil {
  1166. return *m.owner, true
  1167. }
  1168. return
  1169. }
  1170. // OwnerIDs returns the "owner" edge IDs in the mutation.
  1171. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1172. // OwnerID instead. It exists only for internal usage by the builders.
  1173. func (m *AlertMutation) OwnerIDs() (ids []int) {
  1174. if id := m.owner; id != nil {
  1175. ids = append(ids, *id)
  1176. }
  1177. return
  1178. }
  1179. // ResetOwner resets all changes to the "owner" edge.
  1180. func (m *AlertMutation) ResetOwner() {
  1181. m.owner = nil
  1182. m.clearedowner = false
  1183. }
  1184. // AddDecisionIDs adds the "decisions" edge to the Decision entity by ids.
  1185. func (m *AlertMutation) AddDecisionIDs(ids ...int) {
  1186. if m.decisions == nil {
  1187. m.decisions = make(map[int]struct{})
  1188. }
  1189. for i := range ids {
  1190. m.decisions[ids[i]] = struct{}{}
  1191. }
  1192. }
  1193. // ClearDecisions clears the "decisions" edge to the Decision entity.
  1194. func (m *AlertMutation) ClearDecisions() {
  1195. m.cleareddecisions = true
  1196. }
  1197. // DecisionsCleared reports if the "decisions" edge to the Decision entity was cleared.
  1198. func (m *AlertMutation) DecisionsCleared() bool {
  1199. return m.cleareddecisions
  1200. }
  1201. // RemoveDecisionIDs removes the "decisions" edge to the Decision entity by IDs.
  1202. func (m *AlertMutation) RemoveDecisionIDs(ids ...int) {
  1203. if m.removeddecisions == nil {
  1204. m.removeddecisions = make(map[int]struct{})
  1205. }
  1206. for i := range ids {
  1207. delete(m.decisions, ids[i])
  1208. m.removeddecisions[ids[i]] = struct{}{}
  1209. }
  1210. }
  1211. // RemovedDecisions returns the removed IDs of the "decisions" edge to the Decision entity.
  1212. func (m *AlertMutation) RemovedDecisionsIDs() (ids []int) {
  1213. for id := range m.removeddecisions {
  1214. ids = append(ids, id)
  1215. }
  1216. return
  1217. }
  1218. // DecisionsIDs returns the "decisions" edge IDs in the mutation.
  1219. func (m *AlertMutation) DecisionsIDs() (ids []int) {
  1220. for id := range m.decisions {
  1221. ids = append(ids, id)
  1222. }
  1223. return
  1224. }
  1225. // ResetDecisions resets all changes to the "decisions" edge.
  1226. func (m *AlertMutation) ResetDecisions() {
  1227. m.decisions = nil
  1228. m.cleareddecisions = false
  1229. m.removeddecisions = nil
  1230. }
  1231. // AddEventIDs adds the "events" edge to the Event entity by ids.
  1232. func (m *AlertMutation) AddEventIDs(ids ...int) {
  1233. if m.events == nil {
  1234. m.events = make(map[int]struct{})
  1235. }
  1236. for i := range ids {
  1237. m.events[ids[i]] = struct{}{}
  1238. }
  1239. }
  1240. // ClearEvents clears the "events" edge to the Event entity.
  1241. func (m *AlertMutation) ClearEvents() {
  1242. m.clearedevents = true
  1243. }
  1244. // EventsCleared reports if the "events" edge to the Event entity was cleared.
  1245. func (m *AlertMutation) EventsCleared() bool {
  1246. return m.clearedevents
  1247. }
  1248. // RemoveEventIDs removes the "events" edge to the Event entity by IDs.
  1249. func (m *AlertMutation) RemoveEventIDs(ids ...int) {
  1250. if m.removedevents == nil {
  1251. m.removedevents = make(map[int]struct{})
  1252. }
  1253. for i := range ids {
  1254. delete(m.events, ids[i])
  1255. m.removedevents[ids[i]] = struct{}{}
  1256. }
  1257. }
  1258. // RemovedEvents returns the removed IDs of the "events" edge to the Event entity.
  1259. func (m *AlertMutation) RemovedEventsIDs() (ids []int) {
  1260. for id := range m.removedevents {
  1261. ids = append(ids, id)
  1262. }
  1263. return
  1264. }
  1265. // EventsIDs returns the "events" edge IDs in the mutation.
  1266. func (m *AlertMutation) EventsIDs() (ids []int) {
  1267. for id := range m.events {
  1268. ids = append(ids, id)
  1269. }
  1270. return
  1271. }
  1272. // ResetEvents resets all changes to the "events" edge.
  1273. func (m *AlertMutation) ResetEvents() {
  1274. m.events = nil
  1275. m.clearedevents = false
  1276. m.removedevents = nil
  1277. }
  1278. // AddMetaIDs adds the "metas" edge to the Meta entity by ids.
  1279. func (m *AlertMutation) AddMetaIDs(ids ...int) {
  1280. if m.metas == nil {
  1281. m.metas = make(map[int]struct{})
  1282. }
  1283. for i := range ids {
  1284. m.metas[ids[i]] = struct{}{}
  1285. }
  1286. }
  1287. // ClearMetas clears the "metas" edge to the Meta entity.
  1288. func (m *AlertMutation) ClearMetas() {
  1289. m.clearedmetas = true
  1290. }
  1291. // MetasCleared reports if the "metas" edge to the Meta entity was cleared.
  1292. func (m *AlertMutation) MetasCleared() bool {
  1293. return m.clearedmetas
  1294. }
  1295. // RemoveMetaIDs removes the "metas" edge to the Meta entity by IDs.
  1296. func (m *AlertMutation) RemoveMetaIDs(ids ...int) {
  1297. if m.removedmetas == nil {
  1298. m.removedmetas = make(map[int]struct{})
  1299. }
  1300. for i := range ids {
  1301. delete(m.metas, ids[i])
  1302. m.removedmetas[ids[i]] = struct{}{}
  1303. }
  1304. }
  1305. // RemovedMetas returns the removed IDs of the "metas" edge to the Meta entity.
  1306. func (m *AlertMutation) RemovedMetasIDs() (ids []int) {
  1307. for id := range m.removedmetas {
  1308. ids = append(ids, id)
  1309. }
  1310. return
  1311. }
  1312. // MetasIDs returns the "metas" edge IDs in the mutation.
  1313. func (m *AlertMutation) MetasIDs() (ids []int) {
  1314. for id := range m.metas {
  1315. ids = append(ids, id)
  1316. }
  1317. return
  1318. }
  1319. // ResetMetas resets all changes to the "metas" edge.
  1320. func (m *AlertMutation) ResetMetas() {
  1321. m.metas = nil
  1322. m.clearedmetas = false
  1323. m.removedmetas = nil
  1324. }
  1325. // Where appends a list predicates to the AlertMutation builder.
  1326. func (m *AlertMutation) Where(ps ...predicate.Alert) {
  1327. m.predicates = append(m.predicates, ps...)
  1328. }
  1329. // Op returns the operation name.
  1330. func (m *AlertMutation) Op() Op {
  1331. return m.op
  1332. }
  1333. // Type returns the node type of this mutation (Alert).
  1334. func (m *AlertMutation) Type() string {
  1335. return m.typ
  1336. }
  1337. // Fields returns all fields that were changed during this mutation. Note that in
  1338. // order to get all numeric fields that were incremented/decremented, call
  1339. // AddedFields().
  1340. func (m *AlertMutation) Fields() []string {
  1341. fields := make([]string, 0, 22)
  1342. if m.created_at != nil {
  1343. fields = append(fields, alert.FieldCreatedAt)
  1344. }
  1345. if m.updated_at != nil {
  1346. fields = append(fields, alert.FieldUpdatedAt)
  1347. }
  1348. if m.scenario != nil {
  1349. fields = append(fields, alert.FieldScenario)
  1350. }
  1351. if m.bucketId != nil {
  1352. fields = append(fields, alert.FieldBucketId)
  1353. }
  1354. if m.message != nil {
  1355. fields = append(fields, alert.FieldMessage)
  1356. }
  1357. if m.eventsCount != nil {
  1358. fields = append(fields, alert.FieldEventsCount)
  1359. }
  1360. if m.startedAt != nil {
  1361. fields = append(fields, alert.FieldStartedAt)
  1362. }
  1363. if m.stoppedAt != nil {
  1364. fields = append(fields, alert.FieldStoppedAt)
  1365. }
  1366. if m.sourceIp != nil {
  1367. fields = append(fields, alert.FieldSourceIp)
  1368. }
  1369. if m.sourceRange != nil {
  1370. fields = append(fields, alert.FieldSourceRange)
  1371. }
  1372. if m.sourceAsNumber != nil {
  1373. fields = append(fields, alert.FieldSourceAsNumber)
  1374. }
  1375. if m.sourceAsName != nil {
  1376. fields = append(fields, alert.FieldSourceAsName)
  1377. }
  1378. if m.sourceCountry != nil {
  1379. fields = append(fields, alert.FieldSourceCountry)
  1380. }
  1381. if m.sourceLatitude != nil {
  1382. fields = append(fields, alert.FieldSourceLatitude)
  1383. }
  1384. if m.sourceLongitude != nil {
  1385. fields = append(fields, alert.FieldSourceLongitude)
  1386. }
  1387. if m.sourceScope != nil {
  1388. fields = append(fields, alert.FieldSourceScope)
  1389. }
  1390. if m.sourceValue != nil {
  1391. fields = append(fields, alert.FieldSourceValue)
  1392. }
  1393. if m.capacity != nil {
  1394. fields = append(fields, alert.FieldCapacity)
  1395. }
  1396. if m.leakSpeed != nil {
  1397. fields = append(fields, alert.FieldLeakSpeed)
  1398. }
  1399. if m.scenarioVersion != nil {
  1400. fields = append(fields, alert.FieldScenarioVersion)
  1401. }
  1402. if m.scenarioHash != nil {
  1403. fields = append(fields, alert.FieldScenarioHash)
  1404. }
  1405. if m.simulated != nil {
  1406. fields = append(fields, alert.FieldSimulated)
  1407. }
  1408. return fields
  1409. }
  1410. // Field returns the value of a field with the given name. The second boolean
  1411. // return value indicates that this field was not set, or was not defined in the
  1412. // schema.
  1413. func (m *AlertMutation) Field(name string) (ent.Value, bool) {
  1414. switch name {
  1415. case alert.FieldCreatedAt:
  1416. return m.CreatedAt()
  1417. case alert.FieldUpdatedAt:
  1418. return m.UpdatedAt()
  1419. case alert.FieldScenario:
  1420. return m.Scenario()
  1421. case alert.FieldBucketId:
  1422. return m.BucketId()
  1423. case alert.FieldMessage:
  1424. return m.Message()
  1425. case alert.FieldEventsCount:
  1426. return m.EventsCount()
  1427. case alert.FieldStartedAt:
  1428. return m.StartedAt()
  1429. case alert.FieldStoppedAt:
  1430. return m.StoppedAt()
  1431. case alert.FieldSourceIp:
  1432. return m.SourceIp()
  1433. case alert.FieldSourceRange:
  1434. return m.SourceRange()
  1435. case alert.FieldSourceAsNumber:
  1436. return m.SourceAsNumber()
  1437. case alert.FieldSourceAsName:
  1438. return m.SourceAsName()
  1439. case alert.FieldSourceCountry:
  1440. return m.SourceCountry()
  1441. case alert.FieldSourceLatitude:
  1442. return m.SourceLatitude()
  1443. case alert.FieldSourceLongitude:
  1444. return m.SourceLongitude()
  1445. case alert.FieldSourceScope:
  1446. return m.SourceScope()
  1447. case alert.FieldSourceValue:
  1448. return m.SourceValue()
  1449. case alert.FieldCapacity:
  1450. return m.Capacity()
  1451. case alert.FieldLeakSpeed:
  1452. return m.LeakSpeed()
  1453. case alert.FieldScenarioVersion:
  1454. return m.ScenarioVersion()
  1455. case alert.FieldScenarioHash:
  1456. return m.ScenarioHash()
  1457. case alert.FieldSimulated:
  1458. return m.Simulated()
  1459. }
  1460. return nil, false
  1461. }
  1462. // OldField returns the old value of the field from the database. An error is
  1463. // returned if the mutation operation is not UpdateOne, or the query to the
  1464. // database failed.
  1465. func (m *AlertMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1466. switch name {
  1467. case alert.FieldCreatedAt:
  1468. return m.OldCreatedAt(ctx)
  1469. case alert.FieldUpdatedAt:
  1470. return m.OldUpdatedAt(ctx)
  1471. case alert.FieldScenario:
  1472. return m.OldScenario(ctx)
  1473. case alert.FieldBucketId:
  1474. return m.OldBucketId(ctx)
  1475. case alert.FieldMessage:
  1476. return m.OldMessage(ctx)
  1477. case alert.FieldEventsCount:
  1478. return m.OldEventsCount(ctx)
  1479. case alert.FieldStartedAt:
  1480. return m.OldStartedAt(ctx)
  1481. case alert.FieldStoppedAt:
  1482. return m.OldStoppedAt(ctx)
  1483. case alert.FieldSourceIp:
  1484. return m.OldSourceIp(ctx)
  1485. case alert.FieldSourceRange:
  1486. return m.OldSourceRange(ctx)
  1487. case alert.FieldSourceAsNumber:
  1488. return m.OldSourceAsNumber(ctx)
  1489. case alert.FieldSourceAsName:
  1490. return m.OldSourceAsName(ctx)
  1491. case alert.FieldSourceCountry:
  1492. return m.OldSourceCountry(ctx)
  1493. case alert.FieldSourceLatitude:
  1494. return m.OldSourceLatitude(ctx)
  1495. case alert.FieldSourceLongitude:
  1496. return m.OldSourceLongitude(ctx)
  1497. case alert.FieldSourceScope:
  1498. return m.OldSourceScope(ctx)
  1499. case alert.FieldSourceValue:
  1500. return m.OldSourceValue(ctx)
  1501. case alert.FieldCapacity:
  1502. return m.OldCapacity(ctx)
  1503. case alert.FieldLeakSpeed:
  1504. return m.OldLeakSpeed(ctx)
  1505. case alert.FieldScenarioVersion:
  1506. return m.OldScenarioVersion(ctx)
  1507. case alert.FieldScenarioHash:
  1508. return m.OldScenarioHash(ctx)
  1509. case alert.FieldSimulated:
  1510. return m.OldSimulated(ctx)
  1511. }
  1512. return nil, fmt.Errorf("unknown Alert field %s", name)
  1513. }
  1514. // SetField sets the value of a field with the given name. It returns an error if
  1515. // the field is not defined in the schema, or if the type mismatched the field
  1516. // type.
  1517. func (m *AlertMutation) SetField(name string, value ent.Value) error {
  1518. switch name {
  1519. case alert.FieldCreatedAt:
  1520. v, ok := value.(time.Time)
  1521. if !ok {
  1522. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1523. }
  1524. m.SetCreatedAt(v)
  1525. return nil
  1526. case alert.FieldUpdatedAt:
  1527. v, ok := value.(time.Time)
  1528. if !ok {
  1529. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1530. }
  1531. m.SetUpdatedAt(v)
  1532. return nil
  1533. case alert.FieldScenario:
  1534. v, ok := value.(string)
  1535. if !ok {
  1536. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1537. }
  1538. m.SetScenario(v)
  1539. return nil
  1540. case alert.FieldBucketId:
  1541. v, ok := value.(string)
  1542. if !ok {
  1543. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1544. }
  1545. m.SetBucketId(v)
  1546. return nil
  1547. case alert.FieldMessage:
  1548. v, ok := value.(string)
  1549. if !ok {
  1550. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1551. }
  1552. m.SetMessage(v)
  1553. return nil
  1554. case alert.FieldEventsCount:
  1555. v, ok := value.(int32)
  1556. if !ok {
  1557. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1558. }
  1559. m.SetEventsCount(v)
  1560. return nil
  1561. case alert.FieldStartedAt:
  1562. v, ok := value.(time.Time)
  1563. if !ok {
  1564. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1565. }
  1566. m.SetStartedAt(v)
  1567. return nil
  1568. case alert.FieldStoppedAt:
  1569. v, ok := value.(time.Time)
  1570. if !ok {
  1571. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1572. }
  1573. m.SetStoppedAt(v)
  1574. return nil
  1575. case alert.FieldSourceIp:
  1576. v, ok := value.(string)
  1577. if !ok {
  1578. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1579. }
  1580. m.SetSourceIp(v)
  1581. return nil
  1582. case alert.FieldSourceRange:
  1583. v, ok := value.(string)
  1584. if !ok {
  1585. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1586. }
  1587. m.SetSourceRange(v)
  1588. return nil
  1589. case alert.FieldSourceAsNumber:
  1590. v, ok := value.(string)
  1591. if !ok {
  1592. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1593. }
  1594. m.SetSourceAsNumber(v)
  1595. return nil
  1596. case alert.FieldSourceAsName:
  1597. v, ok := value.(string)
  1598. if !ok {
  1599. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1600. }
  1601. m.SetSourceAsName(v)
  1602. return nil
  1603. case alert.FieldSourceCountry:
  1604. v, ok := value.(string)
  1605. if !ok {
  1606. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1607. }
  1608. m.SetSourceCountry(v)
  1609. return nil
  1610. case alert.FieldSourceLatitude:
  1611. v, ok := value.(float32)
  1612. if !ok {
  1613. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1614. }
  1615. m.SetSourceLatitude(v)
  1616. return nil
  1617. case alert.FieldSourceLongitude:
  1618. v, ok := value.(float32)
  1619. if !ok {
  1620. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1621. }
  1622. m.SetSourceLongitude(v)
  1623. return nil
  1624. case alert.FieldSourceScope:
  1625. v, ok := value.(string)
  1626. if !ok {
  1627. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1628. }
  1629. m.SetSourceScope(v)
  1630. return nil
  1631. case alert.FieldSourceValue:
  1632. v, ok := value.(string)
  1633. if !ok {
  1634. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1635. }
  1636. m.SetSourceValue(v)
  1637. return nil
  1638. case alert.FieldCapacity:
  1639. v, ok := value.(int32)
  1640. if !ok {
  1641. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1642. }
  1643. m.SetCapacity(v)
  1644. return nil
  1645. case alert.FieldLeakSpeed:
  1646. v, ok := value.(string)
  1647. if !ok {
  1648. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1649. }
  1650. m.SetLeakSpeed(v)
  1651. return nil
  1652. case alert.FieldScenarioVersion:
  1653. v, ok := value.(string)
  1654. if !ok {
  1655. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1656. }
  1657. m.SetScenarioVersion(v)
  1658. return nil
  1659. case alert.FieldScenarioHash:
  1660. v, ok := value.(string)
  1661. if !ok {
  1662. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1663. }
  1664. m.SetScenarioHash(v)
  1665. return nil
  1666. case alert.FieldSimulated:
  1667. v, ok := value.(bool)
  1668. if !ok {
  1669. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1670. }
  1671. m.SetSimulated(v)
  1672. return nil
  1673. }
  1674. return fmt.Errorf("unknown Alert field %s", name)
  1675. }
  1676. // AddedFields returns all numeric fields that were incremented/decremented during
  1677. // this mutation.
  1678. func (m *AlertMutation) AddedFields() []string {
  1679. var fields []string
  1680. if m.addeventsCount != nil {
  1681. fields = append(fields, alert.FieldEventsCount)
  1682. }
  1683. if m.addsourceLatitude != nil {
  1684. fields = append(fields, alert.FieldSourceLatitude)
  1685. }
  1686. if m.addsourceLongitude != nil {
  1687. fields = append(fields, alert.FieldSourceLongitude)
  1688. }
  1689. if m.addcapacity != nil {
  1690. fields = append(fields, alert.FieldCapacity)
  1691. }
  1692. return fields
  1693. }
  1694. // AddedField returns the numeric value that was incremented/decremented on a field
  1695. // with the given name. The second boolean return value indicates that this field
  1696. // was not set, or was not defined in the schema.
  1697. func (m *AlertMutation) AddedField(name string) (ent.Value, bool) {
  1698. switch name {
  1699. case alert.FieldEventsCount:
  1700. return m.AddedEventsCount()
  1701. case alert.FieldSourceLatitude:
  1702. return m.AddedSourceLatitude()
  1703. case alert.FieldSourceLongitude:
  1704. return m.AddedSourceLongitude()
  1705. case alert.FieldCapacity:
  1706. return m.AddedCapacity()
  1707. }
  1708. return nil, false
  1709. }
  1710. // AddField adds the value to the field with the given name. It returns an error if
  1711. // the field is not defined in the schema, or if the type mismatched the field
  1712. // type.
  1713. func (m *AlertMutation) AddField(name string, value ent.Value) error {
  1714. switch name {
  1715. case alert.FieldEventsCount:
  1716. v, ok := value.(int32)
  1717. if !ok {
  1718. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1719. }
  1720. m.AddEventsCount(v)
  1721. return nil
  1722. case alert.FieldSourceLatitude:
  1723. v, ok := value.(float32)
  1724. if !ok {
  1725. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1726. }
  1727. m.AddSourceLatitude(v)
  1728. return nil
  1729. case alert.FieldSourceLongitude:
  1730. v, ok := value.(float32)
  1731. if !ok {
  1732. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1733. }
  1734. m.AddSourceLongitude(v)
  1735. return nil
  1736. case alert.FieldCapacity:
  1737. v, ok := value.(int32)
  1738. if !ok {
  1739. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1740. }
  1741. m.AddCapacity(v)
  1742. return nil
  1743. }
  1744. return fmt.Errorf("unknown Alert numeric field %s", name)
  1745. }
  1746. // ClearedFields returns all nullable fields that were cleared during this
  1747. // mutation.
  1748. func (m *AlertMutation) ClearedFields() []string {
  1749. var fields []string
  1750. if m.FieldCleared(alert.FieldCreatedAt) {
  1751. fields = append(fields, alert.FieldCreatedAt)
  1752. }
  1753. if m.FieldCleared(alert.FieldUpdatedAt) {
  1754. fields = append(fields, alert.FieldUpdatedAt)
  1755. }
  1756. if m.FieldCleared(alert.FieldBucketId) {
  1757. fields = append(fields, alert.FieldBucketId)
  1758. }
  1759. if m.FieldCleared(alert.FieldMessage) {
  1760. fields = append(fields, alert.FieldMessage)
  1761. }
  1762. if m.FieldCleared(alert.FieldEventsCount) {
  1763. fields = append(fields, alert.FieldEventsCount)
  1764. }
  1765. if m.FieldCleared(alert.FieldStartedAt) {
  1766. fields = append(fields, alert.FieldStartedAt)
  1767. }
  1768. if m.FieldCleared(alert.FieldStoppedAt) {
  1769. fields = append(fields, alert.FieldStoppedAt)
  1770. }
  1771. if m.FieldCleared(alert.FieldSourceIp) {
  1772. fields = append(fields, alert.FieldSourceIp)
  1773. }
  1774. if m.FieldCleared(alert.FieldSourceRange) {
  1775. fields = append(fields, alert.FieldSourceRange)
  1776. }
  1777. if m.FieldCleared(alert.FieldSourceAsNumber) {
  1778. fields = append(fields, alert.FieldSourceAsNumber)
  1779. }
  1780. if m.FieldCleared(alert.FieldSourceAsName) {
  1781. fields = append(fields, alert.FieldSourceAsName)
  1782. }
  1783. if m.FieldCleared(alert.FieldSourceCountry) {
  1784. fields = append(fields, alert.FieldSourceCountry)
  1785. }
  1786. if m.FieldCleared(alert.FieldSourceLatitude) {
  1787. fields = append(fields, alert.FieldSourceLatitude)
  1788. }
  1789. if m.FieldCleared(alert.FieldSourceLongitude) {
  1790. fields = append(fields, alert.FieldSourceLongitude)
  1791. }
  1792. if m.FieldCleared(alert.FieldSourceScope) {
  1793. fields = append(fields, alert.FieldSourceScope)
  1794. }
  1795. if m.FieldCleared(alert.FieldSourceValue) {
  1796. fields = append(fields, alert.FieldSourceValue)
  1797. }
  1798. if m.FieldCleared(alert.FieldCapacity) {
  1799. fields = append(fields, alert.FieldCapacity)
  1800. }
  1801. if m.FieldCleared(alert.FieldLeakSpeed) {
  1802. fields = append(fields, alert.FieldLeakSpeed)
  1803. }
  1804. if m.FieldCleared(alert.FieldScenarioVersion) {
  1805. fields = append(fields, alert.FieldScenarioVersion)
  1806. }
  1807. if m.FieldCleared(alert.FieldScenarioHash) {
  1808. fields = append(fields, alert.FieldScenarioHash)
  1809. }
  1810. return fields
  1811. }
  1812. // FieldCleared returns a boolean indicating if a field with the given name was
  1813. // cleared in this mutation.
  1814. func (m *AlertMutation) FieldCleared(name string) bool {
  1815. _, ok := m.clearedFields[name]
  1816. return ok
  1817. }
  1818. // ClearField clears the value of the field with the given name. It returns an
  1819. // error if the field is not defined in the schema.
  1820. func (m *AlertMutation) ClearField(name string) error {
  1821. switch name {
  1822. case alert.FieldCreatedAt:
  1823. m.ClearCreatedAt()
  1824. return nil
  1825. case alert.FieldUpdatedAt:
  1826. m.ClearUpdatedAt()
  1827. return nil
  1828. case alert.FieldBucketId:
  1829. m.ClearBucketId()
  1830. return nil
  1831. case alert.FieldMessage:
  1832. m.ClearMessage()
  1833. return nil
  1834. case alert.FieldEventsCount:
  1835. m.ClearEventsCount()
  1836. return nil
  1837. case alert.FieldStartedAt:
  1838. m.ClearStartedAt()
  1839. return nil
  1840. case alert.FieldStoppedAt:
  1841. m.ClearStoppedAt()
  1842. return nil
  1843. case alert.FieldSourceIp:
  1844. m.ClearSourceIp()
  1845. return nil
  1846. case alert.FieldSourceRange:
  1847. m.ClearSourceRange()
  1848. return nil
  1849. case alert.FieldSourceAsNumber:
  1850. m.ClearSourceAsNumber()
  1851. return nil
  1852. case alert.FieldSourceAsName:
  1853. m.ClearSourceAsName()
  1854. return nil
  1855. case alert.FieldSourceCountry:
  1856. m.ClearSourceCountry()
  1857. return nil
  1858. case alert.FieldSourceLatitude:
  1859. m.ClearSourceLatitude()
  1860. return nil
  1861. case alert.FieldSourceLongitude:
  1862. m.ClearSourceLongitude()
  1863. return nil
  1864. case alert.FieldSourceScope:
  1865. m.ClearSourceScope()
  1866. return nil
  1867. case alert.FieldSourceValue:
  1868. m.ClearSourceValue()
  1869. return nil
  1870. case alert.FieldCapacity:
  1871. m.ClearCapacity()
  1872. return nil
  1873. case alert.FieldLeakSpeed:
  1874. m.ClearLeakSpeed()
  1875. return nil
  1876. case alert.FieldScenarioVersion:
  1877. m.ClearScenarioVersion()
  1878. return nil
  1879. case alert.FieldScenarioHash:
  1880. m.ClearScenarioHash()
  1881. return nil
  1882. }
  1883. return fmt.Errorf("unknown Alert nullable field %s", name)
  1884. }
  1885. // ResetField resets all changes in the mutation for the field with the given name.
  1886. // It returns an error if the field is not defined in the schema.
  1887. func (m *AlertMutation) ResetField(name string) error {
  1888. switch name {
  1889. case alert.FieldCreatedAt:
  1890. m.ResetCreatedAt()
  1891. return nil
  1892. case alert.FieldUpdatedAt:
  1893. m.ResetUpdatedAt()
  1894. return nil
  1895. case alert.FieldScenario:
  1896. m.ResetScenario()
  1897. return nil
  1898. case alert.FieldBucketId:
  1899. m.ResetBucketId()
  1900. return nil
  1901. case alert.FieldMessage:
  1902. m.ResetMessage()
  1903. return nil
  1904. case alert.FieldEventsCount:
  1905. m.ResetEventsCount()
  1906. return nil
  1907. case alert.FieldStartedAt:
  1908. m.ResetStartedAt()
  1909. return nil
  1910. case alert.FieldStoppedAt:
  1911. m.ResetStoppedAt()
  1912. return nil
  1913. case alert.FieldSourceIp:
  1914. m.ResetSourceIp()
  1915. return nil
  1916. case alert.FieldSourceRange:
  1917. m.ResetSourceRange()
  1918. return nil
  1919. case alert.FieldSourceAsNumber:
  1920. m.ResetSourceAsNumber()
  1921. return nil
  1922. case alert.FieldSourceAsName:
  1923. m.ResetSourceAsName()
  1924. return nil
  1925. case alert.FieldSourceCountry:
  1926. m.ResetSourceCountry()
  1927. return nil
  1928. case alert.FieldSourceLatitude:
  1929. m.ResetSourceLatitude()
  1930. return nil
  1931. case alert.FieldSourceLongitude:
  1932. m.ResetSourceLongitude()
  1933. return nil
  1934. case alert.FieldSourceScope:
  1935. m.ResetSourceScope()
  1936. return nil
  1937. case alert.FieldSourceValue:
  1938. m.ResetSourceValue()
  1939. return nil
  1940. case alert.FieldCapacity:
  1941. m.ResetCapacity()
  1942. return nil
  1943. case alert.FieldLeakSpeed:
  1944. m.ResetLeakSpeed()
  1945. return nil
  1946. case alert.FieldScenarioVersion:
  1947. m.ResetScenarioVersion()
  1948. return nil
  1949. case alert.FieldScenarioHash:
  1950. m.ResetScenarioHash()
  1951. return nil
  1952. case alert.FieldSimulated:
  1953. m.ResetSimulated()
  1954. return nil
  1955. }
  1956. return fmt.Errorf("unknown Alert field %s", name)
  1957. }
  1958. // AddedEdges returns all edge names that were set/added in this mutation.
  1959. func (m *AlertMutation) AddedEdges() []string {
  1960. edges := make([]string, 0, 4)
  1961. if m.owner != nil {
  1962. edges = append(edges, alert.EdgeOwner)
  1963. }
  1964. if m.decisions != nil {
  1965. edges = append(edges, alert.EdgeDecisions)
  1966. }
  1967. if m.events != nil {
  1968. edges = append(edges, alert.EdgeEvents)
  1969. }
  1970. if m.metas != nil {
  1971. edges = append(edges, alert.EdgeMetas)
  1972. }
  1973. return edges
  1974. }
  1975. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1976. // name in this mutation.
  1977. func (m *AlertMutation) AddedIDs(name string) []ent.Value {
  1978. switch name {
  1979. case alert.EdgeOwner:
  1980. if id := m.owner; id != nil {
  1981. return []ent.Value{*id}
  1982. }
  1983. case alert.EdgeDecisions:
  1984. ids := make([]ent.Value, 0, len(m.decisions))
  1985. for id := range m.decisions {
  1986. ids = append(ids, id)
  1987. }
  1988. return ids
  1989. case alert.EdgeEvents:
  1990. ids := make([]ent.Value, 0, len(m.events))
  1991. for id := range m.events {
  1992. ids = append(ids, id)
  1993. }
  1994. return ids
  1995. case alert.EdgeMetas:
  1996. ids := make([]ent.Value, 0, len(m.metas))
  1997. for id := range m.metas {
  1998. ids = append(ids, id)
  1999. }
  2000. return ids
  2001. }
  2002. return nil
  2003. }
  2004. // RemovedEdges returns all edge names that were removed in this mutation.
  2005. func (m *AlertMutation) RemovedEdges() []string {
  2006. edges := make([]string, 0, 4)
  2007. if m.removeddecisions != nil {
  2008. edges = append(edges, alert.EdgeDecisions)
  2009. }
  2010. if m.removedevents != nil {
  2011. edges = append(edges, alert.EdgeEvents)
  2012. }
  2013. if m.removedmetas != nil {
  2014. edges = append(edges, alert.EdgeMetas)
  2015. }
  2016. return edges
  2017. }
  2018. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2019. // the given name in this mutation.
  2020. func (m *AlertMutation) RemovedIDs(name string) []ent.Value {
  2021. switch name {
  2022. case alert.EdgeDecisions:
  2023. ids := make([]ent.Value, 0, len(m.removeddecisions))
  2024. for id := range m.removeddecisions {
  2025. ids = append(ids, id)
  2026. }
  2027. return ids
  2028. case alert.EdgeEvents:
  2029. ids := make([]ent.Value, 0, len(m.removedevents))
  2030. for id := range m.removedevents {
  2031. ids = append(ids, id)
  2032. }
  2033. return ids
  2034. case alert.EdgeMetas:
  2035. ids := make([]ent.Value, 0, len(m.removedmetas))
  2036. for id := range m.removedmetas {
  2037. ids = append(ids, id)
  2038. }
  2039. return ids
  2040. }
  2041. return nil
  2042. }
  2043. // ClearedEdges returns all edge names that were cleared in this mutation.
  2044. func (m *AlertMutation) ClearedEdges() []string {
  2045. edges := make([]string, 0, 4)
  2046. if m.clearedowner {
  2047. edges = append(edges, alert.EdgeOwner)
  2048. }
  2049. if m.cleareddecisions {
  2050. edges = append(edges, alert.EdgeDecisions)
  2051. }
  2052. if m.clearedevents {
  2053. edges = append(edges, alert.EdgeEvents)
  2054. }
  2055. if m.clearedmetas {
  2056. edges = append(edges, alert.EdgeMetas)
  2057. }
  2058. return edges
  2059. }
  2060. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2061. // was cleared in this mutation.
  2062. func (m *AlertMutation) EdgeCleared(name string) bool {
  2063. switch name {
  2064. case alert.EdgeOwner:
  2065. return m.clearedowner
  2066. case alert.EdgeDecisions:
  2067. return m.cleareddecisions
  2068. case alert.EdgeEvents:
  2069. return m.clearedevents
  2070. case alert.EdgeMetas:
  2071. return m.clearedmetas
  2072. }
  2073. return false
  2074. }
  2075. // ClearEdge clears the value of the edge with the given name. It returns an error
  2076. // if that edge is not defined in the schema.
  2077. func (m *AlertMutation) ClearEdge(name string) error {
  2078. switch name {
  2079. case alert.EdgeOwner:
  2080. m.ClearOwner()
  2081. return nil
  2082. }
  2083. return fmt.Errorf("unknown Alert unique edge %s", name)
  2084. }
  2085. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2086. // It returns an error if the edge is not defined in the schema.
  2087. func (m *AlertMutation) ResetEdge(name string) error {
  2088. switch name {
  2089. case alert.EdgeOwner:
  2090. m.ResetOwner()
  2091. return nil
  2092. case alert.EdgeDecisions:
  2093. m.ResetDecisions()
  2094. return nil
  2095. case alert.EdgeEvents:
  2096. m.ResetEvents()
  2097. return nil
  2098. case alert.EdgeMetas:
  2099. m.ResetMetas()
  2100. return nil
  2101. }
  2102. return fmt.Errorf("unknown Alert edge %s", name)
  2103. }
  2104. // BouncerMutation represents an operation that mutates the Bouncer nodes in the graph.
  2105. type BouncerMutation struct {
  2106. config
  2107. op Op
  2108. typ string
  2109. id *int
  2110. created_at *time.Time
  2111. updated_at *time.Time
  2112. name *string
  2113. api_key *string
  2114. revoked *bool
  2115. ip_address *string
  2116. _type *string
  2117. version *string
  2118. until *time.Time
  2119. last_pull *time.Time
  2120. clearedFields map[string]struct{}
  2121. done bool
  2122. oldValue func(context.Context) (*Bouncer, error)
  2123. predicates []predicate.Bouncer
  2124. }
  2125. var _ ent.Mutation = (*BouncerMutation)(nil)
  2126. // bouncerOption allows management of the mutation configuration using functional options.
  2127. type bouncerOption func(*BouncerMutation)
  2128. // newBouncerMutation creates new mutation for the Bouncer entity.
  2129. func newBouncerMutation(c config, op Op, opts ...bouncerOption) *BouncerMutation {
  2130. m := &BouncerMutation{
  2131. config: c,
  2132. op: op,
  2133. typ: TypeBouncer,
  2134. clearedFields: make(map[string]struct{}),
  2135. }
  2136. for _, opt := range opts {
  2137. opt(m)
  2138. }
  2139. return m
  2140. }
  2141. // withBouncerID sets the ID field of the mutation.
  2142. func withBouncerID(id int) bouncerOption {
  2143. return func(m *BouncerMutation) {
  2144. var (
  2145. err error
  2146. once sync.Once
  2147. value *Bouncer
  2148. )
  2149. m.oldValue = func(ctx context.Context) (*Bouncer, error) {
  2150. once.Do(func() {
  2151. if m.done {
  2152. err = fmt.Errorf("querying old values post mutation is not allowed")
  2153. } else {
  2154. value, err = m.Client().Bouncer.Get(ctx, id)
  2155. }
  2156. })
  2157. return value, err
  2158. }
  2159. m.id = &id
  2160. }
  2161. }
  2162. // withBouncer sets the old Bouncer of the mutation.
  2163. func withBouncer(node *Bouncer) bouncerOption {
  2164. return func(m *BouncerMutation) {
  2165. m.oldValue = func(context.Context) (*Bouncer, error) {
  2166. return node, nil
  2167. }
  2168. m.id = &node.ID
  2169. }
  2170. }
  2171. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2172. // executed in a transaction (ent.Tx), a transactional client is returned.
  2173. func (m BouncerMutation) Client() *Client {
  2174. client := &Client{config: m.config}
  2175. client.init()
  2176. return client
  2177. }
  2178. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2179. // it returns an error otherwise.
  2180. func (m BouncerMutation) Tx() (*Tx, error) {
  2181. if _, ok := m.driver.(*txDriver); !ok {
  2182. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  2183. }
  2184. tx := &Tx{config: m.config}
  2185. tx.init()
  2186. return tx, nil
  2187. }
  2188. // ID returns the ID value in the mutation. Note that the ID is only available
  2189. // if it was provided to the builder or after it was returned from the database.
  2190. func (m *BouncerMutation) ID() (id int, exists bool) {
  2191. if m.id == nil {
  2192. return
  2193. }
  2194. return *m.id, true
  2195. }
  2196. // SetCreatedAt sets the "created_at" field.
  2197. func (m *BouncerMutation) SetCreatedAt(t time.Time) {
  2198. m.created_at = &t
  2199. }
  2200. // CreatedAt returns the value of the "created_at" field in the mutation.
  2201. func (m *BouncerMutation) CreatedAt() (r time.Time, exists bool) {
  2202. v := m.created_at
  2203. if v == nil {
  2204. return
  2205. }
  2206. return *v, true
  2207. }
  2208. // OldCreatedAt returns the old "created_at" field's value of the Bouncer entity.
  2209. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2210. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2211. func (m *BouncerMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  2212. if !m.op.Is(OpUpdateOne) {
  2213. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  2214. }
  2215. if m.id == nil || m.oldValue == nil {
  2216. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  2217. }
  2218. oldValue, err := m.oldValue(ctx)
  2219. if err != nil {
  2220. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  2221. }
  2222. return oldValue.CreatedAt, nil
  2223. }
  2224. // ClearCreatedAt clears the value of the "created_at" field.
  2225. func (m *BouncerMutation) ClearCreatedAt() {
  2226. m.created_at = nil
  2227. m.clearedFields[bouncer.FieldCreatedAt] = struct{}{}
  2228. }
  2229. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  2230. func (m *BouncerMutation) CreatedAtCleared() bool {
  2231. _, ok := m.clearedFields[bouncer.FieldCreatedAt]
  2232. return ok
  2233. }
  2234. // ResetCreatedAt resets all changes to the "created_at" field.
  2235. func (m *BouncerMutation) ResetCreatedAt() {
  2236. m.created_at = nil
  2237. delete(m.clearedFields, bouncer.FieldCreatedAt)
  2238. }
  2239. // SetUpdatedAt sets the "updated_at" field.
  2240. func (m *BouncerMutation) SetUpdatedAt(t time.Time) {
  2241. m.updated_at = &t
  2242. }
  2243. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  2244. func (m *BouncerMutation) UpdatedAt() (r time.Time, exists bool) {
  2245. v := m.updated_at
  2246. if v == nil {
  2247. return
  2248. }
  2249. return *v, true
  2250. }
  2251. // OldUpdatedAt returns the old "updated_at" field's value of the Bouncer entity.
  2252. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2253. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2254. func (m *BouncerMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  2255. if !m.op.Is(OpUpdateOne) {
  2256. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  2257. }
  2258. if m.id == nil || m.oldValue == nil {
  2259. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  2260. }
  2261. oldValue, err := m.oldValue(ctx)
  2262. if err != nil {
  2263. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  2264. }
  2265. return oldValue.UpdatedAt, nil
  2266. }
  2267. // ClearUpdatedAt clears the value of the "updated_at" field.
  2268. func (m *BouncerMutation) ClearUpdatedAt() {
  2269. m.updated_at = nil
  2270. m.clearedFields[bouncer.FieldUpdatedAt] = struct{}{}
  2271. }
  2272. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  2273. func (m *BouncerMutation) UpdatedAtCleared() bool {
  2274. _, ok := m.clearedFields[bouncer.FieldUpdatedAt]
  2275. return ok
  2276. }
  2277. // ResetUpdatedAt resets all changes to the "updated_at" field.
  2278. func (m *BouncerMutation) ResetUpdatedAt() {
  2279. m.updated_at = nil
  2280. delete(m.clearedFields, bouncer.FieldUpdatedAt)
  2281. }
  2282. // SetName sets the "name" field.
  2283. func (m *BouncerMutation) SetName(s string) {
  2284. m.name = &s
  2285. }
  2286. // Name returns the value of the "name" field in the mutation.
  2287. func (m *BouncerMutation) Name() (r string, exists bool) {
  2288. v := m.name
  2289. if v == nil {
  2290. return
  2291. }
  2292. return *v, true
  2293. }
  2294. // OldName returns the old "name" field's value of the Bouncer entity.
  2295. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2296. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2297. func (m *BouncerMutation) OldName(ctx context.Context) (v string, err error) {
  2298. if !m.op.Is(OpUpdateOne) {
  2299. return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
  2300. }
  2301. if m.id == nil || m.oldValue == nil {
  2302. return v, fmt.Errorf("OldName requires an ID field in the mutation")
  2303. }
  2304. oldValue, err := m.oldValue(ctx)
  2305. if err != nil {
  2306. return v, fmt.Errorf("querying old value for OldName: %w", err)
  2307. }
  2308. return oldValue.Name, nil
  2309. }
  2310. // ResetName resets all changes to the "name" field.
  2311. func (m *BouncerMutation) ResetName() {
  2312. m.name = nil
  2313. }
  2314. // SetAPIKey sets the "api_key" field.
  2315. func (m *BouncerMutation) SetAPIKey(s string) {
  2316. m.api_key = &s
  2317. }
  2318. // APIKey returns the value of the "api_key" field in the mutation.
  2319. func (m *BouncerMutation) APIKey() (r string, exists bool) {
  2320. v := m.api_key
  2321. if v == nil {
  2322. return
  2323. }
  2324. return *v, true
  2325. }
  2326. // OldAPIKey returns the old "api_key" field's value of the Bouncer entity.
  2327. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2328. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2329. func (m *BouncerMutation) OldAPIKey(ctx context.Context) (v string, err error) {
  2330. if !m.op.Is(OpUpdateOne) {
  2331. return v, fmt.Errorf("OldAPIKey is only allowed on UpdateOne operations")
  2332. }
  2333. if m.id == nil || m.oldValue == nil {
  2334. return v, fmt.Errorf("OldAPIKey requires an ID field in the mutation")
  2335. }
  2336. oldValue, err := m.oldValue(ctx)
  2337. if err != nil {
  2338. return v, fmt.Errorf("querying old value for OldAPIKey: %w", err)
  2339. }
  2340. return oldValue.APIKey, nil
  2341. }
  2342. // ResetAPIKey resets all changes to the "api_key" field.
  2343. func (m *BouncerMutation) ResetAPIKey() {
  2344. m.api_key = nil
  2345. }
  2346. // SetRevoked sets the "revoked" field.
  2347. func (m *BouncerMutation) SetRevoked(b bool) {
  2348. m.revoked = &b
  2349. }
  2350. // Revoked returns the value of the "revoked" field in the mutation.
  2351. func (m *BouncerMutation) Revoked() (r bool, exists bool) {
  2352. v := m.revoked
  2353. if v == nil {
  2354. return
  2355. }
  2356. return *v, true
  2357. }
  2358. // OldRevoked returns the old "revoked" field's value of the Bouncer entity.
  2359. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2360. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2361. func (m *BouncerMutation) OldRevoked(ctx context.Context) (v bool, err error) {
  2362. if !m.op.Is(OpUpdateOne) {
  2363. return v, fmt.Errorf("OldRevoked is only allowed on UpdateOne operations")
  2364. }
  2365. if m.id == nil || m.oldValue == nil {
  2366. return v, fmt.Errorf("OldRevoked requires an ID field in the mutation")
  2367. }
  2368. oldValue, err := m.oldValue(ctx)
  2369. if err != nil {
  2370. return v, fmt.Errorf("querying old value for OldRevoked: %w", err)
  2371. }
  2372. return oldValue.Revoked, nil
  2373. }
  2374. // ResetRevoked resets all changes to the "revoked" field.
  2375. func (m *BouncerMutation) ResetRevoked() {
  2376. m.revoked = nil
  2377. }
  2378. // SetIPAddress sets the "ip_address" field.
  2379. func (m *BouncerMutation) SetIPAddress(s string) {
  2380. m.ip_address = &s
  2381. }
  2382. // IPAddress returns the value of the "ip_address" field in the mutation.
  2383. func (m *BouncerMutation) IPAddress() (r string, exists bool) {
  2384. v := m.ip_address
  2385. if v == nil {
  2386. return
  2387. }
  2388. return *v, true
  2389. }
  2390. // OldIPAddress returns the old "ip_address" field's value of the Bouncer entity.
  2391. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2392. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2393. func (m *BouncerMutation) OldIPAddress(ctx context.Context) (v string, err error) {
  2394. if !m.op.Is(OpUpdateOne) {
  2395. return v, fmt.Errorf("OldIPAddress is only allowed on UpdateOne operations")
  2396. }
  2397. if m.id == nil || m.oldValue == nil {
  2398. return v, fmt.Errorf("OldIPAddress requires an ID field in the mutation")
  2399. }
  2400. oldValue, err := m.oldValue(ctx)
  2401. if err != nil {
  2402. return v, fmt.Errorf("querying old value for OldIPAddress: %w", err)
  2403. }
  2404. return oldValue.IPAddress, nil
  2405. }
  2406. // ClearIPAddress clears the value of the "ip_address" field.
  2407. func (m *BouncerMutation) ClearIPAddress() {
  2408. m.ip_address = nil
  2409. m.clearedFields[bouncer.FieldIPAddress] = struct{}{}
  2410. }
  2411. // IPAddressCleared returns if the "ip_address" field was cleared in this mutation.
  2412. func (m *BouncerMutation) IPAddressCleared() bool {
  2413. _, ok := m.clearedFields[bouncer.FieldIPAddress]
  2414. return ok
  2415. }
  2416. // ResetIPAddress resets all changes to the "ip_address" field.
  2417. func (m *BouncerMutation) ResetIPAddress() {
  2418. m.ip_address = nil
  2419. delete(m.clearedFields, bouncer.FieldIPAddress)
  2420. }
  2421. // SetType sets the "type" field.
  2422. func (m *BouncerMutation) SetType(s string) {
  2423. m._type = &s
  2424. }
  2425. // GetType returns the value of the "type" field in the mutation.
  2426. func (m *BouncerMutation) GetType() (r string, exists bool) {
  2427. v := m._type
  2428. if v == nil {
  2429. return
  2430. }
  2431. return *v, true
  2432. }
  2433. // OldType returns the old "type" field's value of the Bouncer entity.
  2434. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2435. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2436. func (m *BouncerMutation) OldType(ctx context.Context) (v string, err error) {
  2437. if !m.op.Is(OpUpdateOne) {
  2438. return v, fmt.Errorf("OldType is only allowed on UpdateOne operations")
  2439. }
  2440. if m.id == nil || m.oldValue == nil {
  2441. return v, fmt.Errorf("OldType requires an ID field in the mutation")
  2442. }
  2443. oldValue, err := m.oldValue(ctx)
  2444. if err != nil {
  2445. return v, fmt.Errorf("querying old value for OldType: %w", err)
  2446. }
  2447. return oldValue.Type, nil
  2448. }
  2449. // ClearType clears the value of the "type" field.
  2450. func (m *BouncerMutation) ClearType() {
  2451. m._type = nil
  2452. m.clearedFields[bouncer.FieldType] = struct{}{}
  2453. }
  2454. // TypeCleared returns if the "type" field was cleared in this mutation.
  2455. func (m *BouncerMutation) TypeCleared() bool {
  2456. _, ok := m.clearedFields[bouncer.FieldType]
  2457. return ok
  2458. }
  2459. // ResetType resets all changes to the "type" field.
  2460. func (m *BouncerMutation) ResetType() {
  2461. m._type = nil
  2462. delete(m.clearedFields, bouncer.FieldType)
  2463. }
  2464. // SetVersion sets the "version" field.
  2465. func (m *BouncerMutation) SetVersion(s string) {
  2466. m.version = &s
  2467. }
  2468. // Version returns the value of the "version" field in the mutation.
  2469. func (m *BouncerMutation) Version() (r string, exists bool) {
  2470. v := m.version
  2471. if v == nil {
  2472. return
  2473. }
  2474. return *v, true
  2475. }
  2476. // OldVersion returns the old "version" field's value of the Bouncer entity.
  2477. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2478. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2479. func (m *BouncerMutation) OldVersion(ctx context.Context) (v string, err error) {
  2480. if !m.op.Is(OpUpdateOne) {
  2481. return v, fmt.Errorf("OldVersion is only allowed on UpdateOne operations")
  2482. }
  2483. if m.id == nil || m.oldValue == nil {
  2484. return v, fmt.Errorf("OldVersion requires an ID field in the mutation")
  2485. }
  2486. oldValue, err := m.oldValue(ctx)
  2487. if err != nil {
  2488. return v, fmt.Errorf("querying old value for OldVersion: %w", err)
  2489. }
  2490. return oldValue.Version, nil
  2491. }
  2492. // ClearVersion clears the value of the "version" field.
  2493. func (m *BouncerMutation) ClearVersion() {
  2494. m.version = nil
  2495. m.clearedFields[bouncer.FieldVersion] = struct{}{}
  2496. }
  2497. // VersionCleared returns if the "version" field was cleared in this mutation.
  2498. func (m *BouncerMutation) VersionCleared() bool {
  2499. _, ok := m.clearedFields[bouncer.FieldVersion]
  2500. return ok
  2501. }
  2502. // ResetVersion resets all changes to the "version" field.
  2503. func (m *BouncerMutation) ResetVersion() {
  2504. m.version = nil
  2505. delete(m.clearedFields, bouncer.FieldVersion)
  2506. }
  2507. // SetUntil sets the "until" field.
  2508. func (m *BouncerMutation) SetUntil(t time.Time) {
  2509. m.until = &t
  2510. }
  2511. // Until returns the value of the "until" field in the mutation.
  2512. func (m *BouncerMutation) Until() (r time.Time, exists bool) {
  2513. v := m.until
  2514. if v == nil {
  2515. return
  2516. }
  2517. return *v, true
  2518. }
  2519. // OldUntil returns the old "until" field's value of the Bouncer entity.
  2520. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2521. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2522. func (m *BouncerMutation) OldUntil(ctx context.Context) (v time.Time, err error) {
  2523. if !m.op.Is(OpUpdateOne) {
  2524. return v, fmt.Errorf("OldUntil is only allowed on UpdateOne operations")
  2525. }
  2526. if m.id == nil || m.oldValue == nil {
  2527. return v, fmt.Errorf("OldUntil requires an ID field in the mutation")
  2528. }
  2529. oldValue, err := m.oldValue(ctx)
  2530. if err != nil {
  2531. return v, fmt.Errorf("querying old value for OldUntil: %w", err)
  2532. }
  2533. return oldValue.Until, nil
  2534. }
  2535. // ClearUntil clears the value of the "until" field.
  2536. func (m *BouncerMutation) ClearUntil() {
  2537. m.until = nil
  2538. m.clearedFields[bouncer.FieldUntil] = struct{}{}
  2539. }
  2540. // UntilCleared returns if the "until" field was cleared in this mutation.
  2541. func (m *BouncerMutation) UntilCleared() bool {
  2542. _, ok := m.clearedFields[bouncer.FieldUntil]
  2543. return ok
  2544. }
  2545. // ResetUntil resets all changes to the "until" field.
  2546. func (m *BouncerMutation) ResetUntil() {
  2547. m.until = nil
  2548. delete(m.clearedFields, bouncer.FieldUntil)
  2549. }
  2550. // SetLastPull sets the "last_pull" field.
  2551. func (m *BouncerMutation) SetLastPull(t time.Time) {
  2552. m.last_pull = &t
  2553. }
  2554. // LastPull returns the value of the "last_pull" field in the mutation.
  2555. func (m *BouncerMutation) LastPull() (r time.Time, exists bool) {
  2556. v := m.last_pull
  2557. if v == nil {
  2558. return
  2559. }
  2560. return *v, true
  2561. }
  2562. // OldLastPull returns the old "last_pull" field's value of the Bouncer entity.
  2563. // If the Bouncer object wasn't provided to the builder, the object is fetched from the database.
  2564. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2565. func (m *BouncerMutation) OldLastPull(ctx context.Context) (v time.Time, err error) {
  2566. if !m.op.Is(OpUpdateOne) {
  2567. return v, fmt.Errorf("OldLastPull is only allowed on UpdateOne operations")
  2568. }
  2569. if m.id == nil || m.oldValue == nil {
  2570. return v, fmt.Errorf("OldLastPull requires an ID field in the mutation")
  2571. }
  2572. oldValue, err := m.oldValue(ctx)
  2573. if err != nil {
  2574. return v, fmt.Errorf("querying old value for OldLastPull: %w", err)
  2575. }
  2576. return oldValue.LastPull, nil
  2577. }
  2578. // ResetLastPull resets all changes to the "last_pull" field.
  2579. func (m *BouncerMutation) ResetLastPull() {
  2580. m.last_pull = nil
  2581. }
  2582. // Where appends a list predicates to the BouncerMutation builder.
  2583. func (m *BouncerMutation) Where(ps ...predicate.Bouncer) {
  2584. m.predicates = append(m.predicates, ps...)
  2585. }
  2586. // Op returns the operation name.
  2587. func (m *BouncerMutation) Op() Op {
  2588. return m.op
  2589. }
  2590. // Type returns the node type of this mutation (Bouncer).
  2591. func (m *BouncerMutation) Type() string {
  2592. return m.typ
  2593. }
  2594. // Fields returns all fields that were changed during this mutation. Note that in
  2595. // order to get all numeric fields that were incremented/decremented, call
  2596. // AddedFields().
  2597. func (m *BouncerMutation) Fields() []string {
  2598. fields := make([]string, 0, 10)
  2599. if m.created_at != nil {
  2600. fields = append(fields, bouncer.FieldCreatedAt)
  2601. }
  2602. if m.updated_at != nil {
  2603. fields = append(fields, bouncer.FieldUpdatedAt)
  2604. }
  2605. if m.name != nil {
  2606. fields = append(fields, bouncer.FieldName)
  2607. }
  2608. if m.api_key != nil {
  2609. fields = append(fields, bouncer.FieldAPIKey)
  2610. }
  2611. if m.revoked != nil {
  2612. fields = append(fields, bouncer.FieldRevoked)
  2613. }
  2614. if m.ip_address != nil {
  2615. fields = append(fields, bouncer.FieldIPAddress)
  2616. }
  2617. if m._type != nil {
  2618. fields = append(fields, bouncer.FieldType)
  2619. }
  2620. if m.version != nil {
  2621. fields = append(fields, bouncer.FieldVersion)
  2622. }
  2623. if m.until != nil {
  2624. fields = append(fields, bouncer.FieldUntil)
  2625. }
  2626. if m.last_pull != nil {
  2627. fields = append(fields, bouncer.FieldLastPull)
  2628. }
  2629. return fields
  2630. }
  2631. // Field returns the value of a field with the given name. The second boolean
  2632. // return value indicates that this field was not set, or was not defined in the
  2633. // schema.
  2634. func (m *BouncerMutation) Field(name string) (ent.Value, bool) {
  2635. switch name {
  2636. case bouncer.FieldCreatedAt:
  2637. return m.CreatedAt()
  2638. case bouncer.FieldUpdatedAt:
  2639. return m.UpdatedAt()
  2640. case bouncer.FieldName:
  2641. return m.Name()
  2642. case bouncer.FieldAPIKey:
  2643. return m.APIKey()
  2644. case bouncer.FieldRevoked:
  2645. return m.Revoked()
  2646. case bouncer.FieldIPAddress:
  2647. return m.IPAddress()
  2648. case bouncer.FieldType:
  2649. return m.GetType()
  2650. case bouncer.FieldVersion:
  2651. return m.Version()
  2652. case bouncer.FieldUntil:
  2653. return m.Until()
  2654. case bouncer.FieldLastPull:
  2655. return m.LastPull()
  2656. }
  2657. return nil, false
  2658. }
  2659. // OldField returns the old value of the field from the database. An error is
  2660. // returned if the mutation operation is not UpdateOne, or the query to the
  2661. // database failed.
  2662. func (m *BouncerMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2663. switch name {
  2664. case bouncer.FieldCreatedAt:
  2665. return m.OldCreatedAt(ctx)
  2666. case bouncer.FieldUpdatedAt:
  2667. return m.OldUpdatedAt(ctx)
  2668. case bouncer.FieldName:
  2669. return m.OldName(ctx)
  2670. case bouncer.FieldAPIKey:
  2671. return m.OldAPIKey(ctx)
  2672. case bouncer.FieldRevoked:
  2673. return m.OldRevoked(ctx)
  2674. case bouncer.FieldIPAddress:
  2675. return m.OldIPAddress(ctx)
  2676. case bouncer.FieldType:
  2677. return m.OldType(ctx)
  2678. case bouncer.FieldVersion:
  2679. return m.OldVersion(ctx)
  2680. case bouncer.FieldUntil:
  2681. return m.OldUntil(ctx)
  2682. case bouncer.FieldLastPull:
  2683. return m.OldLastPull(ctx)
  2684. }
  2685. return nil, fmt.Errorf("unknown Bouncer field %s", name)
  2686. }
  2687. // SetField sets the value of a field with the given name. It returns an error if
  2688. // the field is not defined in the schema, or if the type mismatched the field
  2689. // type.
  2690. func (m *BouncerMutation) SetField(name string, value ent.Value) error {
  2691. switch name {
  2692. case bouncer.FieldCreatedAt:
  2693. v, ok := value.(time.Time)
  2694. if !ok {
  2695. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2696. }
  2697. m.SetCreatedAt(v)
  2698. return nil
  2699. case bouncer.FieldUpdatedAt:
  2700. v, ok := value.(time.Time)
  2701. if !ok {
  2702. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2703. }
  2704. m.SetUpdatedAt(v)
  2705. return nil
  2706. case bouncer.FieldName:
  2707. v, ok := value.(string)
  2708. if !ok {
  2709. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2710. }
  2711. m.SetName(v)
  2712. return nil
  2713. case bouncer.FieldAPIKey:
  2714. v, ok := value.(string)
  2715. if !ok {
  2716. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2717. }
  2718. m.SetAPIKey(v)
  2719. return nil
  2720. case bouncer.FieldRevoked:
  2721. v, ok := value.(bool)
  2722. if !ok {
  2723. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2724. }
  2725. m.SetRevoked(v)
  2726. return nil
  2727. case bouncer.FieldIPAddress:
  2728. v, ok := value.(string)
  2729. if !ok {
  2730. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2731. }
  2732. m.SetIPAddress(v)
  2733. return nil
  2734. case bouncer.FieldType:
  2735. v, ok := value.(string)
  2736. if !ok {
  2737. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2738. }
  2739. m.SetType(v)
  2740. return nil
  2741. case bouncer.FieldVersion:
  2742. v, ok := value.(string)
  2743. if !ok {
  2744. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2745. }
  2746. m.SetVersion(v)
  2747. return nil
  2748. case bouncer.FieldUntil:
  2749. v, ok := value.(time.Time)
  2750. if !ok {
  2751. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2752. }
  2753. m.SetUntil(v)
  2754. return nil
  2755. case bouncer.FieldLastPull:
  2756. v, ok := value.(time.Time)
  2757. if !ok {
  2758. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2759. }
  2760. m.SetLastPull(v)
  2761. return nil
  2762. }
  2763. return fmt.Errorf("unknown Bouncer field %s", name)
  2764. }
  2765. // AddedFields returns all numeric fields that were incremented/decremented during
  2766. // this mutation.
  2767. func (m *BouncerMutation) AddedFields() []string {
  2768. return nil
  2769. }
  2770. // AddedField returns the numeric value that was incremented/decremented on a field
  2771. // with the given name. The second boolean return value indicates that this field
  2772. // was not set, or was not defined in the schema.
  2773. func (m *BouncerMutation) AddedField(name string) (ent.Value, bool) {
  2774. return nil, false
  2775. }
  2776. // AddField adds the value to the field with the given name. It returns an error if
  2777. // the field is not defined in the schema, or if the type mismatched the field
  2778. // type.
  2779. func (m *BouncerMutation) AddField(name string, value ent.Value) error {
  2780. switch name {
  2781. }
  2782. return fmt.Errorf("unknown Bouncer numeric field %s", name)
  2783. }
  2784. // ClearedFields returns all nullable fields that were cleared during this
  2785. // mutation.
  2786. func (m *BouncerMutation) ClearedFields() []string {
  2787. var fields []string
  2788. if m.FieldCleared(bouncer.FieldCreatedAt) {
  2789. fields = append(fields, bouncer.FieldCreatedAt)
  2790. }
  2791. if m.FieldCleared(bouncer.FieldUpdatedAt) {
  2792. fields = append(fields, bouncer.FieldUpdatedAt)
  2793. }
  2794. if m.FieldCleared(bouncer.FieldIPAddress) {
  2795. fields = append(fields, bouncer.FieldIPAddress)
  2796. }
  2797. if m.FieldCleared(bouncer.FieldType) {
  2798. fields = append(fields, bouncer.FieldType)
  2799. }
  2800. if m.FieldCleared(bouncer.FieldVersion) {
  2801. fields = append(fields, bouncer.FieldVersion)
  2802. }
  2803. if m.FieldCleared(bouncer.FieldUntil) {
  2804. fields = append(fields, bouncer.FieldUntil)
  2805. }
  2806. return fields
  2807. }
  2808. // FieldCleared returns a boolean indicating if a field with the given name was
  2809. // cleared in this mutation.
  2810. func (m *BouncerMutation) FieldCleared(name string) bool {
  2811. _, ok := m.clearedFields[name]
  2812. return ok
  2813. }
  2814. // ClearField clears the value of the field with the given name. It returns an
  2815. // error if the field is not defined in the schema.
  2816. func (m *BouncerMutation) ClearField(name string) error {
  2817. switch name {
  2818. case bouncer.FieldCreatedAt:
  2819. m.ClearCreatedAt()
  2820. return nil
  2821. case bouncer.FieldUpdatedAt:
  2822. m.ClearUpdatedAt()
  2823. return nil
  2824. case bouncer.FieldIPAddress:
  2825. m.ClearIPAddress()
  2826. return nil
  2827. case bouncer.FieldType:
  2828. m.ClearType()
  2829. return nil
  2830. case bouncer.FieldVersion:
  2831. m.ClearVersion()
  2832. return nil
  2833. case bouncer.FieldUntil:
  2834. m.ClearUntil()
  2835. return nil
  2836. }
  2837. return fmt.Errorf("unknown Bouncer nullable field %s", name)
  2838. }
  2839. // ResetField resets all changes in the mutation for the field with the given name.
  2840. // It returns an error if the field is not defined in the schema.
  2841. func (m *BouncerMutation) ResetField(name string) error {
  2842. switch name {
  2843. case bouncer.FieldCreatedAt:
  2844. m.ResetCreatedAt()
  2845. return nil
  2846. case bouncer.FieldUpdatedAt:
  2847. m.ResetUpdatedAt()
  2848. return nil
  2849. case bouncer.FieldName:
  2850. m.ResetName()
  2851. return nil
  2852. case bouncer.FieldAPIKey:
  2853. m.ResetAPIKey()
  2854. return nil
  2855. case bouncer.FieldRevoked:
  2856. m.ResetRevoked()
  2857. return nil
  2858. case bouncer.FieldIPAddress:
  2859. m.ResetIPAddress()
  2860. return nil
  2861. case bouncer.FieldType:
  2862. m.ResetType()
  2863. return nil
  2864. case bouncer.FieldVersion:
  2865. m.ResetVersion()
  2866. return nil
  2867. case bouncer.FieldUntil:
  2868. m.ResetUntil()
  2869. return nil
  2870. case bouncer.FieldLastPull:
  2871. m.ResetLastPull()
  2872. return nil
  2873. }
  2874. return fmt.Errorf("unknown Bouncer field %s", name)
  2875. }
  2876. // AddedEdges returns all edge names that were set/added in this mutation.
  2877. func (m *BouncerMutation) AddedEdges() []string {
  2878. edges := make([]string, 0, 0)
  2879. return edges
  2880. }
  2881. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2882. // name in this mutation.
  2883. func (m *BouncerMutation) AddedIDs(name string) []ent.Value {
  2884. return nil
  2885. }
  2886. // RemovedEdges returns all edge names that were removed in this mutation.
  2887. func (m *BouncerMutation) RemovedEdges() []string {
  2888. edges := make([]string, 0, 0)
  2889. return edges
  2890. }
  2891. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2892. // the given name in this mutation.
  2893. func (m *BouncerMutation) RemovedIDs(name string) []ent.Value {
  2894. return nil
  2895. }
  2896. // ClearedEdges returns all edge names that were cleared in this mutation.
  2897. func (m *BouncerMutation) ClearedEdges() []string {
  2898. edges := make([]string, 0, 0)
  2899. return edges
  2900. }
  2901. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2902. // was cleared in this mutation.
  2903. func (m *BouncerMutation) EdgeCleared(name string) bool {
  2904. return false
  2905. }
  2906. // ClearEdge clears the value of the edge with the given name. It returns an error
  2907. // if that edge is not defined in the schema.
  2908. func (m *BouncerMutation) ClearEdge(name string) error {
  2909. return fmt.Errorf("unknown Bouncer unique edge %s", name)
  2910. }
  2911. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2912. // It returns an error if the edge is not defined in the schema.
  2913. func (m *BouncerMutation) ResetEdge(name string) error {
  2914. return fmt.Errorf("unknown Bouncer edge %s", name)
  2915. }
  2916. // DecisionMutation represents an operation that mutates the Decision nodes in the graph.
  2917. type DecisionMutation struct {
  2918. config
  2919. op Op
  2920. typ string
  2921. id *int
  2922. created_at *time.Time
  2923. updated_at *time.Time
  2924. until *time.Time
  2925. scenario *string
  2926. _type *string
  2927. start_ip *int64
  2928. addstart_ip *int64
  2929. end_ip *int64
  2930. addend_ip *int64
  2931. start_suffix *int64
  2932. addstart_suffix *int64
  2933. end_suffix *int64
  2934. addend_suffix *int64
  2935. ip_size *int64
  2936. addip_size *int64
  2937. scope *string
  2938. value *string
  2939. origin *string
  2940. simulated *bool
  2941. clearedFields map[string]struct{}
  2942. owner *int
  2943. clearedowner bool
  2944. done bool
  2945. oldValue func(context.Context) (*Decision, error)
  2946. predicates []predicate.Decision
  2947. }
  2948. var _ ent.Mutation = (*DecisionMutation)(nil)
  2949. // decisionOption allows management of the mutation configuration using functional options.
  2950. type decisionOption func(*DecisionMutation)
  2951. // newDecisionMutation creates new mutation for the Decision entity.
  2952. func newDecisionMutation(c config, op Op, opts ...decisionOption) *DecisionMutation {
  2953. m := &DecisionMutation{
  2954. config: c,
  2955. op: op,
  2956. typ: TypeDecision,
  2957. clearedFields: make(map[string]struct{}),
  2958. }
  2959. for _, opt := range opts {
  2960. opt(m)
  2961. }
  2962. return m
  2963. }
  2964. // withDecisionID sets the ID field of the mutation.
  2965. func withDecisionID(id int) decisionOption {
  2966. return func(m *DecisionMutation) {
  2967. var (
  2968. err error
  2969. once sync.Once
  2970. value *Decision
  2971. )
  2972. m.oldValue = func(ctx context.Context) (*Decision, error) {
  2973. once.Do(func() {
  2974. if m.done {
  2975. err = fmt.Errorf("querying old values post mutation is not allowed")
  2976. } else {
  2977. value, err = m.Client().Decision.Get(ctx, id)
  2978. }
  2979. })
  2980. return value, err
  2981. }
  2982. m.id = &id
  2983. }
  2984. }
  2985. // withDecision sets the old Decision of the mutation.
  2986. func withDecision(node *Decision) decisionOption {
  2987. return func(m *DecisionMutation) {
  2988. m.oldValue = func(context.Context) (*Decision, error) {
  2989. return node, nil
  2990. }
  2991. m.id = &node.ID
  2992. }
  2993. }
  2994. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2995. // executed in a transaction (ent.Tx), a transactional client is returned.
  2996. func (m DecisionMutation) Client() *Client {
  2997. client := &Client{config: m.config}
  2998. client.init()
  2999. return client
  3000. }
  3001. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3002. // it returns an error otherwise.
  3003. func (m DecisionMutation) Tx() (*Tx, error) {
  3004. if _, ok := m.driver.(*txDriver); !ok {
  3005. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  3006. }
  3007. tx := &Tx{config: m.config}
  3008. tx.init()
  3009. return tx, nil
  3010. }
  3011. // ID returns the ID value in the mutation. Note that the ID is only available
  3012. // if it was provided to the builder or after it was returned from the database.
  3013. func (m *DecisionMutation) ID() (id int, exists bool) {
  3014. if m.id == nil {
  3015. return
  3016. }
  3017. return *m.id, true
  3018. }
  3019. // SetCreatedAt sets the "created_at" field.
  3020. func (m *DecisionMutation) SetCreatedAt(t time.Time) {
  3021. m.created_at = &t
  3022. }
  3023. // CreatedAt returns the value of the "created_at" field in the mutation.
  3024. func (m *DecisionMutation) CreatedAt() (r time.Time, exists bool) {
  3025. v := m.created_at
  3026. if v == nil {
  3027. return
  3028. }
  3029. return *v, true
  3030. }
  3031. // OldCreatedAt returns the old "created_at" field's value of the Decision entity.
  3032. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3033. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3034. func (m *DecisionMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  3035. if !m.op.Is(OpUpdateOne) {
  3036. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  3037. }
  3038. if m.id == nil || m.oldValue == nil {
  3039. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  3040. }
  3041. oldValue, err := m.oldValue(ctx)
  3042. if err != nil {
  3043. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  3044. }
  3045. return oldValue.CreatedAt, nil
  3046. }
  3047. // ClearCreatedAt clears the value of the "created_at" field.
  3048. func (m *DecisionMutation) ClearCreatedAt() {
  3049. m.created_at = nil
  3050. m.clearedFields[decision.FieldCreatedAt] = struct{}{}
  3051. }
  3052. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  3053. func (m *DecisionMutation) CreatedAtCleared() bool {
  3054. _, ok := m.clearedFields[decision.FieldCreatedAt]
  3055. return ok
  3056. }
  3057. // ResetCreatedAt resets all changes to the "created_at" field.
  3058. func (m *DecisionMutation) ResetCreatedAt() {
  3059. m.created_at = nil
  3060. delete(m.clearedFields, decision.FieldCreatedAt)
  3061. }
  3062. // SetUpdatedAt sets the "updated_at" field.
  3063. func (m *DecisionMutation) SetUpdatedAt(t time.Time) {
  3064. m.updated_at = &t
  3065. }
  3066. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  3067. func (m *DecisionMutation) UpdatedAt() (r time.Time, exists bool) {
  3068. v := m.updated_at
  3069. if v == nil {
  3070. return
  3071. }
  3072. return *v, true
  3073. }
  3074. // OldUpdatedAt returns the old "updated_at" field's value of the Decision entity.
  3075. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3076. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3077. func (m *DecisionMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  3078. if !m.op.Is(OpUpdateOne) {
  3079. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  3080. }
  3081. if m.id == nil || m.oldValue == nil {
  3082. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  3083. }
  3084. oldValue, err := m.oldValue(ctx)
  3085. if err != nil {
  3086. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  3087. }
  3088. return oldValue.UpdatedAt, nil
  3089. }
  3090. // ClearUpdatedAt clears the value of the "updated_at" field.
  3091. func (m *DecisionMutation) ClearUpdatedAt() {
  3092. m.updated_at = nil
  3093. m.clearedFields[decision.FieldUpdatedAt] = struct{}{}
  3094. }
  3095. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  3096. func (m *DecisionMutation) UpdatedAtCleared() bool {
  3097. _, ok := m.clearedFields[decision.FieldUpdatedAt]
  3098. return ok
  3099. }
  3100. // ResetUpdatedAt resets all changes to the "updated_at" field.
  3101. func (m *DecisionMutation) ResetUpdatedAt() {
  3102. m.updated_at = nil
  3103. delete(m.clearedFields, decision.FieldUpdatedAt)
  3104. }
  3105. // SetUntil sets the "until" field.
  3106. func (m *DecisionMutation) SetUntil(t time.Time) {
  3107. m.until = &t
  3108. }
  3109. // Until returns the value of the "until" field in the mutation.
  3110. func (m *DecisionMutation) Until() (r time.Time, exists bool) {
  3111. v := m.until
  3112. if v == nil {
  3113. return
  3114. }
  3115. return *v, true
  3116. }
  3117. // OldUntil returns the old "until" field's value of the Decision entity.
  3118. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3119. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3120. func (m *DecisionMutation) OldUntil(ctx context.Context) (v time.Time, err error) {
  3121. if !m.op.Is(OpUpdateOne) {
  3122. return v, fmt.Errorf("OldUntil is only allowed on UpdateOne operations")
  3123. }
  3124. if m.id == nil || m.oldValue == nil {
  3125. return v, fmt.Errorf("OldUntil requires an ID field in the mutation")
  3126. }
  3127. oldValue, err := m.oldValue(ctx)
  3128. if err != nil {
  3129. return v, fmt.Errorf("querying old value for OldUntil: %w", err)
  3130. }
  3131. return oldValue.Until, nil
  3132. }
  3133. // ResetUntil resets all changes to the "until" field.
  3134. func (m *DecisionMutation) ResetUntil() {
  3135. m.until = nil
  3136. }
  3137. // SetScenario sets the "scenario" field.
  3138. func (m *DecisionMutation) SetScenario(s string) {
  3139. m.scenario = &s
  3140. }
  3141. // Scenario returns the value of the "scenario" field in the mutation.
  3142. func (m *DecisionMutation) Scenario() (r string, exists bool) {
  3143. v := m.scenario
  3144. if v == nil {
  3145. return
  3146. }
  3147. return *v, true
  3148. }
  3149. // OldScenario returns the old "scenario" field's value of the Decision entity.
  3150. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3151. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3152. func (m *DecisionMutation) OldScenario(ctx context.Context) (v string, err error) {
  3153. if !m.op.Is(OpUpdateOne) {
  3154. return v, fmt.Errorf("OldScenario is only allowed on UpdateOne operations")
  3155. }
  3156. if m.id == nil || m.oldValue == nil {
  3157. return v, fmt.Errorf("OldScenario requires an ID field in the mutation")
  3158. }
  3159. oldValue, err := m.oldValue(ctx)
  3160. if err != nil {
  3161. return v, fmt.Errorf("querying old value for OldScenario: %w", err)
  3162. }
  3163. return oldValue.Scenario, nil
  3164. }
  3165. // ResetScenario resets all changes to the "scenario" field.
  3166. func (m *DecisionMutation) ResetScenario() {
  3167. m.scenario = nil
  3168. }
  3169. // SetType sets the "type" field.
  3170. func (m *DecisionMutation) SetType(s string) {
  3171. m._type = &s
  3172. }
  3173. // GetType returns the value of the "type" field in the mutation.
  3174. func (m *DecisionMutation) GetType() (r string, exists bool) {
  3175. v := m._type
  3176. if v == nil {
  3177. return
  3178. }
  3179. return *v, true
  3180. }
  3181. // OldType returns the old "type" field's value of the Decision entity.
  3182. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3183. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3184. func (m *DecisionMutation) OldType(ctx context.Context) (v string, err error) {
  3185. if !m.op.Is(OpUpdateOne) {
  3186. return v, fmt.Errorf("OldType is only allowed on UpdateOne operations")
  3187. }
  3188. if m.id == nil || m.oldValue == nil {
  3189. return v, fmt.Errorf("OldType requires an ID field in the mutation")
  3190. }
  3191. oldValue, err := m.oldValue(ctx)
  3192. if err != nil {
  3193. return v, fmt.Errorf("querying old value for OldType: %w", err)
  3194. }
  3195. return oldValue.Type, nil
  3196. }
  3197. // ResetType resets all changes to the "type" field.
  3198. func (m *DecisionMutation) ResetType() {
  3199. m._type = nil
  3200. }
  3201. // SetStartIP sets the "start_ip" field.
  3202. func (m *DecisionMutation) SetStartIP(i int64) {
  3203. m.start_ip = &i
  3204. m.addstart_ip = nil
  3205. }
  3206. // StartIP returns the value of the "start_ip" field in the mutation.
  3207. func (m *DecisionMutation) StartIP() (r int64, exists bool) {
  3208. v := m.start_ip
  3209. if v == nil {
  3210. return
  3211. }
  3212. return *v, true
  3213. }
  3214. // OldStartIP returns the old "start_ip" field's value of the Decision entity.
  3215. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3216. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3217. func (m *DecisionMutation) OldStartIP(ctx context.Context) (v int64, err error) {
  3218. if !m.op.Is(OpUpdateOne) {
  3219. return v, fmt.Errorf("OldStartIP is only allowed on UpdateOne operations")
  3220. }
  3221. if m.id == nil || m.oldValue == nil {
  3222. return v, fmt.Errorf("OldStartIP requires an ID field in the mutation")
  3223. }
  3224. oldValue, err := m.oldValue(ctx)
  3225. if err != nil {
  3226. return v, fmt.Errorf("querying old value for OldStartIP: %w", err)
  3227. }
  3228. return oldValue.StartIP, nil
  3229. }
  3230. // AddStartIP adds i to the "start_ip" field.
  3231. func (m *DecisionMutation) AddStartIP(i int64) {
  3232. if m.addstart_ip != nil {
  3233. *m.addstart_ip += i
  3234. } else {
  3235. m.addstart_ip = &i
  3236. }
  3237. }
  3238. // AddedStartIP returns the value that was added to the "start_ip" field in this mutation.
  3239. func (m *DecisionMutation) AddedStartIP() (r int64, exists bool) {
  3240. v := m.addstart_ip
  3241. if v == nil {
  3242. return
  3243. }
  3244. return *v, true
  3245. }
  3246. // ClearStartIP clears the value of the "start_ip" field.
  3247. func (m *DecisionMutation) ClearStartIP() {
  3248. m.start_ip = nil
  3249. m.addstart_ip = nil
  3250. m.clearedFields[decision.FieldStartIP] = struct{}{}
  3251. }
  3252. // StartIPCleared returns if the "start_ip" field was cleared in this mutation.
  3253. func (m *DecisionMutation) StartIPCleared() bool {
  3254. _, ok := m.clearedFields[decision.FieldStartIP]
  3255. return ok
  3256. }
  3257. // ResetStartIP resets all changes to the "start_ip" field.
  3258. func (m *DecisionMutation) ResetStartIP() {
  3259. m.start_ip = nil
  3260. m.addstart_ip = nil
  3261. delete(m.clearedFields, decision.FieldStartIP)
  3262. }
  3263. // SetEndIP sets the "end_ip" field.
  3264. func (m *DecisionMutation) SetEndIP(i int64) {
  3265. m.end_ip = &i
  3266. m.addend_ip = nil
  3267. }
  3268. // EndIP returns the value of the "end_ip" field in the mutation.
  3269. func (m *DecisionMutation) EndIP() (r int64, exists bool) {
  3270. v := m.end_ip
  3271. if v == nil {
  3272. return
  3273. }
  3274. return *v, true
  3275. }
  3276. // OldEndIP returns the old "end_ip" field's value of the Decision entity.
  3277. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3278. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3279. func (m *DecisionMutation) OldEndIP(ctx context.Context) (v int64, err error) {
  3280. if !m.op.Is(OpUpdateOne) {
  3281. return v, fmt.Errorf("OldEndIP is only allowed on UpdateOne operations")
  3282. }
  3283. if m.id == nil || m.oldValue == nil {
  3284. return v, fmt.Errorf("OldEndIP requires an ID field in the mutation")
  3285. }
  3286. oldValue, err := m.oldValue(ctx)
  3287. if err != nil {
  3288. return v, fmt.Errorf("querying old value for OldEndIP: %w", err)
  3289. }
  3290. return oldValue.EndIP, nil
  3291. }
  3292. // AddEndIP adds i to the "end_ip" field.
  3293. func (m *DecisionMutation) AddEndIP(i int64) {
  3294. if m.addend_ip != nil {
  3295. *m.addend_ip += i
  3296. } else {
  3297. m.addend_ip = &i
  3298. }
  3299. }
  3300. // AddedEndIP returns the value that was added to the "end_ip" field in this mutation.
  3301. func (m *DecisionMutation) AddedEndIP() (r int64, exists bool) {
  3302. v := m.addend_ip
  3303. if v == nil {
  3304. return
  3305. }
  3306. return *v, true
  3307. }
  3308. // ClearEndIP clears the value of the "end_ip" field.
  3309. func (m *DecisionMutation) ClearEndIP() {
  3310. m.end_ip = nil
  3311. m.addend_ip = nil
  3312. m.clearedFields[decision.FieldEndIP] = struct{}{}
  3313. }
  3314. // EndIPCleared returns if the "end_ip" field was cleared in this mutation.
  3315. func (m *DecisionMutation) EndIPCleared() bool {
  3316. _, ok := m.clearedFields[decision.FieldEndIP]
  3317. return ok
  3318. }
  3319. // ResetEndIP resets all changes to the "end_ip" field.
  3320. func (m *DecisionMutation) ResetEndIP() {
  3321. m.end_ip = nil
  3322. m.addend_ip = nil
  3323. delete(m.clearedFields, decision.FieldEndIP)
  3324. }
  3325. // SetStartSuffix sets the "start_suffix" field.
  3326. func (m *DecisionMutation) SetStartSuffix(i int64) {
  3327. m.start_suffix = &i
  3328. m.addstart_suffix = nil
  3329. }
  3330. // StartSuffix returns the value of the "start_suffix" field in the mutation.
  3331. func (m *DecisionMutation) StartSuffix() (r int64, exists bool) {
  3332. v := m.start_suffix
  3333. if v == nil {
  3334. return
  3335. }
  3336. return *v, true
  3337. }
  3338. // OldStartSuffix returns the old "start_suffix" field's value of the Decision entity.
  3339. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3340. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3341. func (m *DecisionMutation) OldStartSuffix(ctx context.Context) (v int64, err error) {
  3342. if !m.op.Is(OpUpdateOne) {
  3343. return v, fmt.Errorf("OldStartSuffix is only allowed on UpdateOne operations")
  3344. }
  3345. if m.id == nil || m.oldValue == nil {
  3346. return v, fmt.Errorf("OldStartSuffix requires an ID field in the mutation")
  3347. }
  3348. oldValue, err := m.oldValue(ctx)
  3349. if err != nil {
  3350. return v, fmt.Errorf("querying old value for OldStartSuffix: %w", err)
  3351. }
  3352. return oldValue.StartSuffix, nil
  3353. }
  3354. // AddStartSuffix adds i to the "start_suffix" field.
  3355. func (m *DecisionMutation) AddStartSuffix(i int64) {
  3356. if m.addstart_suffix != nil {
  3357. *m.addstart_suffix += i
  3358. } else {
  3359. m.addstart_suffix = &i
  3360. }
  3361. }
  3362. // AddedStartSuffix returns the value that was added to the "start_suffix" field in this mutation.
  3363. func (m *DecisionMutation) AddedStartSuffix() (r int64, exists bool) {
  3364. v := m.addstart_suffix
  3365. if v == nil {
  3366. return
  3367. }
  3368. return *v, true
  3369. }
  3370. // ClearStartSuffix clears the value of the "start_suffix" field.
  3371. func (m *DecisionMutation) ClearStartSuffix() {
  3372. m.start_suffix = nil
  3373. m.addstart_suffix = nil
  3374. m.clearedFields[decision.FieldStartSuffix] = struct{}{}
  3375. }
  3376. // StartSuffixCleared returns if the "start_suffix" field was cleared in this mutation.
  3377. func (m *DecisionMutation) StartSuffixCleared() bool {
  3378. _, ok := m.clearedFields[decision.FieldStartSuffix]
  3379. return ok
  3380. }
  3381. // ResetStartSuffix resets all changes to the "start_suffix" field.
  3382. func (m *DecisionMutation) ResetStartSuffix() {
  3383. m.start_suffix = nil
  3384. m.addstart_suffix = nil
  3385. delete(m.clearedFields, decision.FieldStartSuffix)
  3386. }
  3387. // SetEndSuffix sets the "end_suffix" field.
  3388. func (m *DecisionMutation) SetEndSuffix(i int64) {
  3389. m.end_suffix = &i
  3390. m.addend_suffix = nil
  3391. }
  3392. // EndSuffix returns the value of the "end_suffix" field in the mutation.
  3393. func (m *DecisionMutation) EndSuffix() (r int64, exists bool) {
  3394. v := m.end_suffix
  3395. if v == nil {
  3396. return
  3397. }
  3398. return *v, true
  3399. }
  3400. // OldEndSuffix returns the old "end_suffix" field's value of the Decision entity.
  3401. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3402. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3403. func (m *DecisionMutation) OldEndSuffix(ctx context.Context) (v int64, err error) {
  3404. if !m.op.Is(OpUpdateOne) {
  3405. return v, fmt.Errorf("OldEndSuffix is only allowed on UpdateOne operations")
  3406. }
  3407. if m.id == nil || m.oldValue == nil {
  3408. return v, fmt.Errorf("OldEndSuffix requires an ID field in the mutation")
  3409. }
  3410. oldValue, err := m.oldValue(ctx)
  3411. if err != nil {
  3412. return v, fmt.Errorf("querying old value for OldEndSuffix: %w", err)
  3413. }
  3414. return oldValue.EndSuffix, nil
  3415. }
  3416. // AddEndSuffix adds i to the "end_suffix" field.
  3417. func (m *DecisionMutation) AddEndSuffix(i int64) {
  3418. if m.addend_suffix != nil {
  3419. *m.addend_suffix += i
  3420. } else {
  3421. m.addend_suffix = &i
  3422. }
  3423. }
  3424. // AddedEndSuffix returns the value that was added to the "end_suffix" field in this mutation.
  3425. func (m *DecisionMutation) AddedEndSuffix() (r int64, exists bool) {
  3426. v := m.addend_suffix
  3427. if v == nil {
  3428. return
  3429. }
  3430. return *v, true
  3431. }
  3432. // ClearEndSuffix clears the value of the "end_suffix" field.
  3433. func (m *DecisionMutation) ClearEndSuffix() {
  3434. m.end_suffix = nil
  3435. m.addend_suffix = nil
  3436. m.clearedFields[decision.FieldEndSuffix] = struct{}{}
  3437. }
  3438. // EndSuffixCleared returns if the "end_suffix" field was cleared in this mutation.
  3439. func (m *DecisionMutation) EndSuffixCleared() bool {
  3440. _, ok := m.clearedFields[decision.FieldEndSuffix]
  3441. return ok
  3442. }
  3443. // ResetEndSuffix resets all changes to the "end_suffix" field.
  3444. func (m *DecisionMutation) ResetEndSuffix() {
  3445. m.end_suffix = nil
  3446. m.addend_suffix = nil
  3447. delete(m.clearedFields, decision.FieldEndSuffix)
  3448. }
  3449. // SetIPSize sets the "ip_size" field.
  3450. func (m *DecisionMutation) SetIPSize(i int64) {
  3451. m.ip_size = &i
  3452. m.addip_size = nil
  3453. }
  3454. // IPSize returns the value of the "ip_size" field in the mutation.
  3455. func (m *DecisionMutation) IPSize() (r int64, exists bool) {
  3456. v := m.ip_size
  3457. if v == nil {
  3458. return
  3459. }
  3460. return *v, true
  3461. }
  3462. // OldIPSize returns the old "ip_size" field's value of the Decision entity.
  3463. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3464. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3465. func (m *DecisionMutation) OldIPSize(ctx context.Context) (v int64, err error) {
  3466. if !m.op.Is(OpUpdateOne) {
  3467. return v, fmt.Errorf("OldIPSize is only allowed on UpdateOne operations")
  3468. }
  3469. if m.id == nil || m.oldValue == nil {
  3470. return v, fmt.Errorf("OldIPSize requires an ID field in the mutation")
  3471. }
  3472. oldValue, err := m.oldValue(ctx)
  3473. if err != nil {
  3474. return v, fmt.Errorf("querying old value for OldIPSize: %w", err)
  3475. }
  3476. return oldValue.IPSize, nil
  3477. }
  3478. // AddIPSize adds i to the "ip_size" field.
  3479. func (m *DecisionMutation) AddIPSize(i int64) {
  3480. if m.addip_size != nil {
  3481. *m.addip_size += i
  3482. } else {
  3483. m.addip_size = &i
  3484. }
  3485. }
  3486. // AddedIPSize returns the value that was added to the "ip_size" field in this mutation.
  3487. func (m *DecisionMutation) AddedIPSize() (r int64, exists bool) {
  3488. v := m.addip_size
  3489. if v == nil {
  3490. return
  3491. }
  3492. return *v, true
  3493. }
  3494. // ClearIPSize clears the value of the "ip_size" field.
  3495. func (m *DecisionMutation) ClearIPSize() {
  3496. m.ip_size = nil
  3497. m.addip_size = nil
  3498. m.clearedFields[decision.FieldIPSize] = struct{}{}
  3499. }
  3500. // IPSizeCleared returns if the "ip_size" field was cleared in this mutation.
  3501. func (m *DecisionMutation) IPSizeCleared() bool {
  3502. _, ok := m.clearedFields[decision.FieldIPSize]
  3503. return ok
  3504. }
  3505. // ResetIPSize resets all changes to the "ip_size" field.
  3506. func (m *DecisionMutation) ResetIPSize() {
  3507. m.ip_size = nil
  3508. m.addip_size = nil
  3509. delete(m.clearedFields, decision.FieldIPSize)
  3510. }
  3511. // SetScope sets the "scope" field.
  3512. func (m *DecisionMutation) SetScope(s string) {
  3513. m.scope = &s
  3514. }
  3515. // Scope returns the value of the "scope" field in the mutation.
  3516. func (m *DecisionMutation) Scope() (r string, exists bool) {
  3517. v := m.scope
  3518. if v == nil {
  3519. return
  3520. }
  3521. return *v, true
  3522. }
  3523. // OldScope returns the old "scope" field's value of the Decision entity.
  3524. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3525. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3526. func (m *DecisionMutation) OldScope(ctx context.Context) (v string, err error) {
  3527. if !m.op.Is(OpUpdateOne) {
  3528. return v, fmt.Errorf("OldScope is only allowed on UpdateOne operations")
  3529. }
  3530. if m.id == nil || m.oldValue == nil {
  3531. return v, fmt.Errorf("OldScope requires an ID field in the mutation")
  3532. }
  3533. oldValue, err := m.oldValue(ctx)
  3534. if err != nil {
  3535. return v, fmt.Errorf("querying old value for OldScope: %w", err)
  3536. }
  3537. return oldValue.Scope, nil
  3538. }
  3539. // ResetScope resets all changes to the "scope" field.
  3540. func (m *DecisionMutation) ResetScope() {
  3541. m.scope = nil
  3542. }
  3543. // SetValue sets the "value" field.
  3544. func (m *DecisionMutation) SetValue(s string) {
  3545. m.value = &s
  3546. }
  3547. // Value returns the value of the "value" field in the mutation.
  3548. func (m *DecisionMutation) Value() (r string, exists bool) {
  3549. v := m.value
  3550. if v == nil {
  3551. return
  3552. }
  3553. return *v, true
  3554. }
  3555. // OldValue returns the old "value" field's value of the Decision entity.
  3556. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3557. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3558. func (m *DecisionMutation) OldValue(ctx context.Context) (v string, err error) {
  3559. if !m.op.Is(OpUpdateOne) {
  3560. return v, fmt.Errorf("OldValue is only allowed on UpdateOne operations")
  3561. }
  3562. if m.id == nil || m.oldValue == nil {
  3563. return v, fmt.Errorf("OldValue requires an ID field in the mutation")
  3564. }
  3565. oldValue, err := m.oldValue(ctx)
  3566. if err != nil {
  3567. return v, fmt.Errorf("querying old value for OldValue: %w", err)
  3568. }
  3569. return oldValue.Value, nil
  3570. }
  3571. // ResetValue resets all changes to the "value" field.
  3572. func (m *DecisionMutation) ResetValue() {
  3573. m.value = nil
  3574. }
  3575. // SetOrigin sets the "origin" field.
  3576. func (m *DecisionMutation) SetOrigin(s string) {
  3577. m.origin = &s
  3578. }
  3579. // Origin returns the value of the "origin" field in the mutation.
  3580. func (m *DecisionMutation) Origin() (r string, exists bool) {
  3581. v := m.origin
  3582. if v == nil {
  3583. return
  3584. }
  3585. return *v, true
  3586. }
  3587. // OldOrigin returns the old "origin" field's value of the Decision entity.
  3588. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3589. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3590. func (m *DecisionMutation) OldOrigin(ctx context.Context) (v string, err error) {
  3591. if !m.op.Is(OpUpdateOne) {
  3592. return v, fmt.Errorf("OldOrigin is only allowed on UpdateOne operations")
  3593. }
  3594. if m.id == nil || m.oldValue == nil {
  3595. return v, fmt.Errorf("OldOrigin requires an ID field in the mutation")
  3596. }
  3597. oldValue, err := m.oldValue(ctx)
  3598. if err != nil {
  3599. return v, fmt.Errorf("querying old value for OldOrigin: %w", err)
  3600. }
  3601. return oldValue.Origin, nil
  3602. }
  3603. // ResetOrigin resets all changes to the "origin" field.
  3604. func (m *DecisionMutation) ResetOrigin() {
  3605. m.origin = nil
  3606. }
  3607. // SetSimulated sets the "simulated" field.
  3608. func (m *DecisionMutation) SetSimulated(b bool) {
  3609. m.simulated = &b
  3610. }
  3611. // Simulated returns the value of the "simulated" field in the mutation.
  3612. func (m *DecisionMutation) Simulated() (r bool, exists bool) {
  3613. v := m.simulated
  3614. if v == nil {
  3615. return
  3616. }
  3617. return *v, true
  3618. }
  3619. // OldSimulated returns the old "simulated" field's value of the Decision entity.
  3620. // If the Decision object wasn't provided to the builder, the object is fetched from the database.
  3621. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3622. func (m *DecisionMutation) OldSimulated(ctx context.Context) (v bool, err error) {
  3623. if !m.op.Is(OpUpdateOne) {
  3624. return v, fmt.Errorf("OldSimulated is only allowed on UpdateOne operations")
  3625. }
  3626. if m.id == nil || m.oldValue == nil {
  3627. return v, fmt.Errorf("OldSimulated requires an ID field in the mutation")
  3628. }
  3629. oldValue, err := m.oldValue(ctx)
  3630. if err != nil {
  3631. return v, fmt.Errorf("querying old value for OldSimulated: %w", err)
  3632. }
  3633. return oldValue.Simulated, nil
  3634. }
  3635. // ResetSimulated resets all changes to the "simulated" field.
  3636. func (m *DecisionMutation) ResetSimulated() {
  3637. m.simulated = nil
  3638. }
  3639. // SetOwnerID sets the "owner" edge to the Alert entity by id.
  3640. func (m *DecisionMutation) SetOwnerID(id int) {
  3641. m.owner = &id
  3642. }
  3643. // ClearOwner clears the "owner" edge to the Alert entity.
  3644. func (m *DecisionMutation) ClearOwner() {
  3645. m.clearedowner = true
  3646. }
  3647. // OwnerCleared reports if the "owner" edge to the Alert entity was cleared.
  3648. func (m *DecisionMutation) OwnerCleared() bool {
  3649. return m.clearedowner
  3650. }
  3651. // OwnerID returns the "owner" edge ID in the mutation.
  3652. func (m *DecisionMutation) OwnerID() (id int, exists bool) {
  3653. if m.owner != nil {
  3654. return *m.owner, true
  3655. }
  3656. return
  3657. }
  3658. // OwnerIDs returns the "owner" edge IDs in the mutation.
  3659. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  3660. // OwnerID instead. It exists only for internal usage by the builders.
  3661. func (m *DecisionMutation) OwnerIDs() (ids []int) {
  3662. if id := m.owner; id != nil {
  3663. ids = append(ids, *id)
  3664. }
  3665. return
  3666. }
  3667. // ResetOwner resets all changes to the "owner" edge.
  3668. func (m *DecisionMutation) ResetOwner() {
  3669. m.owner = nil
  3670. m.clearedowner = false
  3671. }
  3672. // Where appends a list predicates to the DecisionMutation builder.
  3673. func (m *DecisionMutation) Where(ps ...predicate.Decision) {
  3674. m.predicates = append(m.predicates, ps...)
  3675. }
  3676. // Op returns the operation name.
  3677. func (m *DecisionMutation) Op() Op {
  3678. return m.op
  3679. }
  3680. // Type returns the node type of this mutation (Decision).
  3681. func (m *DecisionMutation) Type() string {
  3682. return m.typ
  3683. }
  3684. // Fields returns all fields that were changed during this mutation. Note that in
  3685. // order to get all numeric fields that were incremented/decremented, call
  3686. // AddedFields().
  3687. func (m *DecisionMutation) Fields() []string {
  3688. fields := make([]string, 0, 14)
  3689. if m.created_at != nil {
  3690. fields = append(fields, decision.FieldCreatedAt)
  3691. }
  3692. if m.updated_at != nil {
  3693. fields = append(fields, decision.FieldUpdatedAt)
  3694. }
  3695. if m.until != nil {
  3696. fields = append(fields, decision.FieldUntil)
  3697. }
  3698. if m.scenario != nil {
  3699. fields = append(fields, decision.FieldScenario)
  3700. }
  3701. if m._type != nil {
  3702. fields = append(fields, decision.FieldType)
  3703. }
  3704. if m.start_ip != nil {
  3705. fields = append(fields, decision.FieldStartIP)
  3706. }
  3707. if m.end_ip != nil {
  3708. fields = append(fields, decision.FieldEndIP)
  3709. }
  3710. if m.start_suffix != nil {
  3711. fields = append(fields, decision.FieldStartSuffix)
  3712. }
  3713. if m.end_suffix != nil {
  3714. fields = append(fields, decision.FieldEndSuffix)
  3715. }
  3716. if m.ip_size != nil {
  3717. fields = append(fields, decision.FieldIPSize)
  3718. }
  3719. if m.scope != nil {
  3720. fields = append(fields, decision.FieldScope)
  3721. }
  3722. if m.value != nil {
  3723. fields = append(fields, decision.FieldValue)
  3724. }
  3725. if m.origin != nil {
  3726. fields = append(fields, decision.FieldOrigin)
  3727. }
  3728. if m.simulated != nil {
  3729. fields = append(fields, decision.FieldSimulated)
  3730. }
  3731. return fields
  3732. }
  3733. // Field returns the value of a field with the given name. The second boolean
  3734. // return value indicates that this field was not set, or was not defined in the
  3735. // schema.
  3736. func (m *DecisionMutation) Field(name string) (ent.Value, bool) {
  3737. switch name {
  3738. case decision.FieldCreatedAt:
  3739. return m.CreatedAt()
  3740. case decision.FieldUpdatedAt:
  3741. return m.UpdatedAt()
  3742. case decision.FieldUntil:
  3743. return m.Until()
  3744. case decision.FieldScenario:
  3745. return m.Scenario()
  3746. case decision.FieldType:
  3747. return m.GetType()
  3748. case decision.FieldStartIP:
  3749. return m.StartIP()
  3750. case decision.FieldEndIP:
  3751. return m.EndIP()
  3752. case decision.FieldStartSuffix:
  3753. return m.StartSuffix()
  3754. case decision.FieldEndSuffix:
  3755. return m.EndSuffix()
  3756. case decision.FieldIPSize:
  3757. return m.IPSize()
  3758. case decision.FieldScope:
  3759. return m.Scope()
  3760. case decision.FieldValue:
  3761. return m.Value()
  3762. case decision.FieldOrigin:
  3763. return m.Origin()
  3764. case decision.FieldSimulated:
  3765. return m.Simulated()
  3766. }
  3767. return nil, false
  3768. }
  3769. // OldField returns the old value of the field from the database. An error is
  3770. // returned if the mutation operation is not UpdateOne, or the query to the
  3771. // database failed.
  3772. func (m *DecisionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  3773. switch name {
  3774. case decision.FieldCreatedAt:
  3775. return m.OldCreatedAt(ctx)
  3776. case decision.FieldUpdatedAt:
  3777. return m.OldUpdatedAt(ctx)
  3778. case decision.FieldUntil:
  3779. return m.OldUntil(ctx)
  3780. case decision.FieldScenario:
  3781. return m.OldScenario(ctx)
  3782. case decision.FieldType:
  3783. return m.OldType(ctx)
  3784. case decision.FieldStartIP:
  3785. return m.OldStartIP(ctx)
  3786. case decision.FieldEndIP:
  3787. return m.OldEndIP(ctx)
  3788. case decision.FieldStartSuffix:
  3789. return m.OldStartSuffix(ctx)
  3790. case decision.FieldEndSuffix:
  3791. return m.OldEndSuffix(ctx)
  3792. case decision.FieldIPSize:
  3793. return m.OldIPSize(ctx)
  3794. case decision.FieldScope:
  3795. return m.OldScope(ctx)
  3796. case decision.FieldValue:
  3797. return m.OldValue(ctx)
  3798. case decision.FieldOrigin:
  3799. return m.OldOrigin(ctx)
  3800. case decision.FieldSimulated:
  3801. return m.OldSimulated(ctx)
  3802. }
  3803. return nil, fmt.Errorf("unknown Decision field %s", name)
  3804. }
  3805. // SetField sets the value of a field with the given name. It returns an error if
  3806. // the field is not defined in the schema, or if the type mismatched the field
  3807. // type.
  3808. func (m *DecisionMutation) SetField(name string, value ent.Value) error {
  3809. switch name {
  3810. case decision.FieldCreatedAt:
  3811. v, ok := value.(time.Time)
  3812. if !ok {
  3813. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3814. }
  3815. m.SetCreatedAt(v)
  3816. return nil
  3817. case decision.FieldUpdatedAt:
  3818. v, ok := value.(time.Time)
  3819. if !ok {
  3820. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3821. }
  3822. m.SetUpdatedAt(v)
  3823. return nil
  3824. case decision.FieldUntil:
  3825. v, ok := value.(time.Time)
  3826. if !ok {
  3827. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3828. }
  3829. m.SetUntil(v)
  3830. return nil
  3831. case decision.FieldScenario:
  3832. v, ok := value.(string)
  3833. if !ok {
  3834. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3835. }
  3836. m.SetScenario(v)
  3837. return nil
  3838. case decision.FieldType:
  3839. v, ok := value.(string)
  3840. if !ok {
  3841. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3842. }
  3843. m.SetType(v)
  3844. return nil
  3845. case decision.FieldStartIP:
  3846. v, ok := value.(int64)
  3847. if !ok {
  3848. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3849. }
  3850. m.SetStartIP(v)
  3851. return nil
  3852. case decision.FieldEndIP:
  3853. v, ok := value.(int64)
  3854. if !ok {
  3855. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3856. }
  3857. m.SetEndIP(v)
  3858. return nil
  3859. case decision.FieldStartSuffix:
  3860. v, ok := value.(int64)
  3861. if !ok {
  3862. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3863. }
  3864. m.SetStartSuffix(v)
  3865. return nil
  3866. case decision.FieldEndSuffix:
  3867. v, ok := value.(int64)
  3868. if !ok {
  3869. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3870. }
  3871. m.SetEndSuffix(v)
  3872. return nil
  3873. case decision.FieldIPSize:
  3874. v, ok := value.(int64)
  3875. if !ok {
  3876. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3877. }
  3878. m.SetIPSize(v)
  3879. return nil
  3880. case decision.FieldScope:
  3881. v, ok := value.(string)
  3882. if !ok {
  3883. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3884. }
  3885. m.SetScope(v)
  3886. return nil
  3887. case decision.FieldValue:
  3888. v, ok := value.(string)
  3889. if !ok {
  3890. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3891. }
  3892. m.SetValue(v)
  3893. return nil
  3894. case decision.FieldOrigin:
  3895. v, ok := value.(string)
  3896. if !ok {
  3897. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3898. }
  3899. m.SetOrigin(v)
  3900. return nil
  3901. case decision.FieldSimulated:
  3902. v, ok := value.(bool)
  3903. if !ok {
  3904. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3905. }
  3906. m.SetSimulated(v)
  3907. return nil
  3908. }
  3909. return fmt.Errorf("unknown Decision field %s", name)
  3910. }
  3911. // AddedFields returns all numeric fields that were incremented/decremented during
  3912. // this mutation.
  3913. func (m *DecisionMutation) AddedFields() []string {
  3914. var fields []string
  3915. if m.addstart_ip != nil {
  3916. fields = append(fields, decision.FieldStartIP)
  3917. }
  3918. if m.addend_ip != nil {
  3919. fields = append(fields, decision.FieldEndIP)
  3920. }
  3921. if m.addstart_suffix != nil {
  3922. fields = append(fields, decision.FieldStartSuffix)
  3923. }
  3924. if m.addend_suffix != nil {
  3925. fields = append(fields, decision.FieldEndSuffix)
  3926. }
  3927. if m.addip_size != nil {
  3928. fields = append(fields, decision.FieldIPSize)
  3929. }
  3930. return fields
  3931. }
  3932. // AddedField returns the numeric value that was incremented/decremented on a field
  3933. // with the given name. The second boolean return value indicates that this field
  3934. // was not set, or was not defined in the schema.
  3935. func (m *DecisionMutation) AddedField(name string) (ent.Value, bool) {
  3936. switch name {
  3937. case decision.FieldStartIP:
  3938. return m.AddedStartIP()
  3939. case decision.FieldEndIP:
  3940. return m.AddedEndIP()
  3941. case decision.FieldStartSuffix:
  3942. return m.AddedStartSuffix()
  3943. case decision.FieldEndSuffix:
  3944. return m.AddedEndSuffix()
  3945. case decision.FieldIPSize:
  3946. return m.AddedIPSize()
  3947. }
  3948. return nil, false
  3949. }
  3950. // AddField adds the value to the field with the given name. It returns an error if
  3951. // the field is not defined in the schema, or if the type mismatched the field
  3952. // type.
  3953. func (m *DecisionMutation) AddField(name string, value ent.Value) error {
  3954. switch name {
  3955. case decision.FieldStartIP:
  3956. v, ok := value.(int64)
  3957. if !ok {
  3958. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3959. }
  3960. m.AddStartIP(v)
  3961. return nil
  3962. case decision.FieldEndIP:
  3963. v, ok := value.(int64)
  3964. if !ok {
  3965. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3966. }
  3967. m.AddEndIP(v)
  3968. return nil
  3969. case decision.FieldStartSuffix:
  3970. v, ok := value.(int64)
  3971. if !ok {
  3972. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3973. }
  3974. m.AddStartSuffix(v)
  3975. return nil
  3976. case decision.FieldEndSuffix:
  3977. v, ok := value.(int64)
  3978. if !ok {
  3979. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3980. }
  3981. m.AddEndSuffix(v)
  3982. return nil
  3983. case decision.FieldIPSize:
  3984. v, ok := value.(int64)
  3985. if !ok {
  3986. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3987. }
  3988. m.AddIPSize(v)
  3989. return nil
  3990. }
  3991. return fmt.Errorf("unknown Decision numeric field %s", name)
  3992. }
  3993. // ClearedFields returns all nullable fields that were cleared during this
  3994. // mutation.
  3995. func (m *DecisionMutation) ClearedFields() []string {
  3996. var fields []string
  3997. if m.FieldCleared(decision.FieldCreatedAt) {
  3998. fields = append(fields, decision.FieldCreatedAt)
  3999. }
  4000. if m.FieldCleared(decision.FieldUpdatedAt) {
  4001. fields = append(fields, decision.FieldUpdatedAt)
  4002. }
  4003. if m.FieldCleared(decision.FieldStartIP) {
  4004. fields = append(fields, decision.FieldStartIP)
  4005. }
  4006. if m.FieldCleared(decision.FieldEndIP) {
  4007. fields = append(fields, decision.FieldEndIP)
  4008. }
  4009. if m.FieldCleared(decision.FieldStartSuffix) {
  4010. fields = append(fields, decision.FieldStartSuffix)
  4011. }
  4012. if m.FieldCleared(decision.FieldEndSuffix) {
  4013. fields = append(fields, decision.FieldEndSuffix)
  4014. }
  4015. if m.FieldCleared(decision.FieldIPSize) {
  4016. fields = append(fields, decision.FieldIPSize)
  4017. }
  4018. return fields
  4019. }
  4020. // FieldCleared returns a boolean indicating if a field with the given name was
  4021. // cleared in this mutation.
  4022. func (m *DecisionMutation) FieldCleared(name string) bool {
  4023. _, ok := m.clearedFields[name]
  4024. return ok
  4025. }
  4026. // ClearField clears the value of the field with the given name. It returns an
  4027. // error if the field is not defined in the schema.
  4028. func (m *DecisionMutation) ClearField(name string) error {
  4029. switch name {
  4030. case decision.FieldCreatedAt:
  4031. m.ClearCreatedAt()
  4032. return nil
  4033. case decision.FieldUpdatedAt:
  4034. m.ClearUpdatedAt()
  4035. return nil
  4036. case decision.FieldStartIP:
  4037. m.ClearStartIP()
  4038. return nil
  4039. case decision.FieldEndIP:
  4040. m.ClearEndIP()
  4041. return nil
  4042. case decision.FieldStartSuffix:
  4043. m.ClearStartSuffix()
  4044. return nil
  4045. case decision.FieldEndSuffix:
  4046. m.ClearEndSuffix()
  4047. return nil
  4048. case decision.FieldIPSize:
  4049. m.ClearIPSize()
  4050. return nil
  4051. }
  4052. return fmt.Errorf("unknown Decision nullable field %s", name)
  4053. }
  4054. // ResetField resets all changes in the mutation for the field with the given name.
  4055. // It returns an error if the field is not defined in the schema.
  4056. func (m *DecisionMutation) ResetField(name string) error {
  4057. switch name {
  4058. case decision.FieldCreatedAt:
  4059. m.ResetCreatedAt()
  4060. return nil
  4061. case decision.FieldUpdatedAt:
  4062. m.ResetUpdatedAt()
  4063. return nil
  4064. case decision.FieldUntil:
  4065. m.ResetUntil()
  4066. return nil
  4067. case decision.FieldScenario:
  4068. m.ResetScenario()
  4069. return nil
  4070. case decision.FieldType:
  4071. m.ResetType()
  4072. return nil
  4073. case decision.FieldStartIP:
  4074. m.ResetStartIP()
  4075. return nil
  4076. case decision.FieldEndIP:
  4077. m.ResetEndIP()
  4078. return nil
  4079. case decision.FieldStartSuffix:
  4080. m.ResetStartSuffix()
  4081. return nil
  4082. case decision.FieldEndSuffix:
  4083. m.ResetEndSuffix()
  4084. return nil
  4085. case decision.FieldIPSize:
  4086. m.ResetIPSize()
  4087. return nil
  4088. case decision.FieldScope:
  4089. m.ResetScope()
  4090. return nil
  4091. case decision.FieldValue:
  4092. m.ResetValue()
  4093. return nil
  4094. case decision.FieldOrigin:
  4095. m.ResetOrigin()
  4096. return nil
  4097. case decision.FieldSimulated:
  4098. m.ResetSimulated()
  4099. return nil
  4100. }
  4101. return fmt.Errorf("unknown Decision field %s", name)
  4102. }
  4103. // AddedEdges returns all edge names that were set/added in this mutation.
  4104. func (m *DecisionMutation) AddedEdges() []string {
  4105. edges := make([]string, 0, 1)
  4106. if m.owner != nil {
  4107. edges = append(edges, decision.EdgeOwner)
  4108. }
  4109. return edges
  4110. }
  4111. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  4112. // name in this mutation.
  4113. func (m *DecisionMutation) AddedIDs(name string) []ent.Value {
  4114. switch name {
  4115. case decision.EdgeOwner:
  4116. if id := m.owner; id != nil {
  4117. return []ent.Value{*id}
  4118. }
  4119. }
  4120. return nil
  4121. }
  4122. // RemovedEdges returns all edge names that were removed in this mutation.
  4123. func (m *DecisionMutation) RemovedEdges() []string {
  4124. edges := make([]string, 0, 1)
  4125. return edges
  4126. }
  4127. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  4128. // the given name in this mutation.
  4129. func (m *DecisionMutation) RemovedIDs(name string) []ent.Value {
  4130. switch name {
  4131. }
  4132. return nil
  4133. }
  4134. // ClearedEdges returns all edge names that were cleared in this mutation.
  4135. func (m *DecisionMutation) ClearedEdges() []string {
  4136. edges := make([]string, 0, 1)
  4137. if m.clearedowner {
  4138. edges = append(edges, decision.EdgeOwner)
  4139. }
  4140. return edges
  4141. }
  4142. // EdgeCleared returns a boolean which indicates if the edge with the given name
  4143. // was cleared in this mutation.
  4144. func (m *DecisionMutation) EdgeCleared(name string) bool {
  4145. switch name {
  4146. case decision.EdgeOwner:
  4147. return m.clearedowner
  4148. }
  4149. return false
  4150. }
  4151. // ClearEdge clears the value of the edge with the given name. It returns an error
  4152. // if that edge is not defined in the schema.
  4153. func (m *DecisionMutation) ClearEdge(name string) error {
  4154. switch name {
  4155. case decision.EdgeOwner:
  4156. m.ClearOwner()
  4157. return nil
  4158. }
  4159. return fmt.Errorf("unknown Decision unique edge %s", name)
  4160. }
  4161. // ResetEdge resets all changes to the edge with the given name in this mutation.
  4162. // It returns an error if the edge is not defined in the schema.
  4163. func (m *DecisionMutation) ResetEdge(name string) error {
  4164. switch name {
  4165. case decision.EdgeOwner:
  4166. m.ResetOwner()
  4167. return nil
  4168. }
  4169. return fmt.Errorf("unknown Decision edge %s", name)
  4170. }
  4171. // EventMutation represents an operation that mutates the Event nodes in the graph.
  4172. type EventMutation struct {
  4173. config
  4174. op Op
  4175. typ string
  4176. id *int
  4177. created_at *time.Time
  4178. updated_at *time.Time
  4179. time *time.Time
  4180. serialized *string
  4181. clearedFields map[string]struct{}
  4182. owner *int
  4183. clearedowner bool
  4184. done bool
  4185. oldValue func(context.Context) (*Event, error)
  4186. predicates []predicate.Event
  4187. }
  4188. var _ ent.Mutation = (*EventMutation)(nil)
  4189. // eventOption allows management of the mutation configuration using functional options.
  4190. type eventOption func(*EventMutation)
  4191. // newEventMutation creates new mutation for the Event entity.
  4192. func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation {
  4193. m := &EventMutation{
  4194. config: c,
  4195. op: op,
  4196. typ: TypeEvent,
  4197. clearedFields: make(map[string]struct{}),
  4198. }
  4199. for _, opt := range opts {
  4200. opt(m)
  4201. }
  4202. return m
  4203. }
  4204. // withEventID sets the ID field of the mutation.
  4205. func withEventID(id int) eventOption {
  4206. return func(m *EventMutation) {
  4207. var (
  4208. err error
  4209. once sync.Once
  4210. value *Event
  4211. )
  4212. m.oldValue = func(ctx context.Context) (*Event, error) {
  4213. once.Do(func() {
  4214. if m.done {
  4215. err = fmt.Errorf("querying old values post mutation is not allowed")
  4216. } else {
  4217. value, err = m.Client().Event.Get(ctx, id)
  4218. }
  4219. })
  4220. return value, err
  4221. }
  4222. m.id = &id
  4223. }
  4224. }
  4225. // withEvent sets the old Event of the mutation.
  4226. func withEvent(node *Event) eventOption {
  4227. return func(m *EventMutation) {
  4228. m.oldValue = func(context.Context) (*Event, error) {
  4229. return node, nil
  4230. }
  4231. m.id = &node.ID
  4232. }
  4233. }
  4234. // Client returns a new `ent.Client` from the mutation. If the mutation was
  4235. // executed in a transaction (ent.Tx), a transactional client is returned.
  4236. func (m EventMutation) Client() *Client {
  4237. client := &Client{config: m.config}
  4238. client.init()
  4239. return client
  4240. }
  4241. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  4242. // it returns an error otherwise.
  4243. func (m EventMutation) Tx() (*Tx, error) {
  4244. if _, ok := m.driver.(*txDriver); !ok {
  4245. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  4246. }
  4247. tx := &Tx{config: m.config}
  4248. tx.init()
  4249. return tx, nil
  4250. }
  4251. // ID returns the ID value in the mutation. Note that the ID is only available
  4252. // if it was provided to the builder or after it was returned from the database.
  4253. func (m *EventMutation) ID() (id int, exists bool) {
  4254. if m.id == nil {
  4255. return
  4256. }
  4257. return *m.id, true
  4258. }
  4259. // SetCreatedAt sets the "created_at" field.
  4260. func (m *EventMutation) SetCreatedAt(t time.Time) {
  4261. m.created_at = &t
  4262. }
  4263. // CreatedAt returns the value of the "created_at" field in the mutation.
  4264. func (m *EventMutation) CreatedAt() (r time.Time, exists bool) {
  4265. v := m.created_at
  4266. if v == nil {
  4267. return
  4268. }
  4269. return *v, true
  4270. }
  4271. // OldCreatedAt returns the old "created_at" field's value of the Event entity.
  4272. // If the Event object wasn't provided to the builder, the object is fetched from the database.
  4273. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4274. func (m *EventMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  4275. if !m.op.Is(OpUpdateOne) {
  4276. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  4277. }
  4278. if m.id == nil || m.oldValue == nil {
  4279. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  4280. }
  4281. oldValue, err := m.oldValue(ctx)
  4282. if err != nil {
  4283. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  4284. }
  4285. return oldValue.CreatedAt, nil
  4286. }
  4287. // ClearCreatedAt clears the value of the "created_at" field.
  4288. func (m *EventMutation) ClearCreatedAt() {
  4289. m.created_at = nil
  4290. m.clearedFields[event.FieldCreatedAt] = struct{}{}
  4291. }
  4292. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  4293. func (m *EventMutation) CreatedAtCleared() bool {
  4294. _, ok := m.clearedFields[event.FieldCreatedAt]
  4295. return ok
  4296. }
  4297. // ResetCreatedAt resets all changes to the "created_at" field.
  4298. func (m *EventMutation) ResetCreatedAt() {
  4299. m.created_at = nil
  4300. delete(m.clearedFields, event.FieldCreatedAt)
  4301. }
  4302. // SetUpdatedAt sets the "updated_at" field.
  4303. func (m *EventMutation) SetUpdatedAt(t time.Time) {
  4304. m.updated_at = &t
  4305. }
  4306. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  4307. func (m *EventMutation) UpdatedAt() (r time.Time, exists bool) {
  4308. v := m.updated_at
  4309. if v == nil {
  4310. return
  4311. }
  4312. return *v, true
  4313. }
  4314. // OldUpdatedAt returns the old "updated_at" field's value of the Event entity.
  4315. // If the Event object wasn't provided to the builder, the object is fetched from the database.
  4316. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4317. func (m *EventMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  4318. if !m.op.Is(OpUpdateOne) {
  4319. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  4320. }
  4321. if m.id == nil || m.oldValue == nil {
  4322. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  4323. }
  4324. oldValue, err := m.oldValue(ctx)
  4325. if err != nil {
  4326. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  4327. }
  4328. return oldValue.UpdatedAt, nil
  4329. }
  4330. // ClearUpdatedAt clears the value of the "updated_at" field.
  4331. func (m *EventMutation) ClearUpdatedAt() {
  4332. m.updated_at = nil
  4333. m.clearedFields[event.FieldUpdatedAt] = struct{}{}
  4334. }
  4335. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  4336. func (m *EventMutation) UpdatedAtCleared() bool {
  4337. _, ok := m.clearedFields[event.FieldUpdatedAt]
  4338. return ok
  4339. }
  4340. // ResetUpdatedAt resets all changes to the "updated_at" field.
  4341. func (m *EventMutation) ResetUpdatedAt() {
  4342. m.updated_at = nil
  4343. delete(m.clearedFields, event.FieldUpdatedAt)
  4344. }
  4345. // SetTime sets the "time" field.
  4346. func (m *EventMutation) SetTime(t time.Time) {
  4347. m.time = &t
  4348. }
  4349. // Time returns the value of the "time" field in the mutation.
  4350. func (m *EventMutation) Time() (r time.Time, exists bool) {
  4351. v := m.time
  4352. if v == nil {
  4353. return
  4354. }
  4355. return *v, true
  4356. }
  4357. // OldTime returns the old "time" field's value of the Event entity.
  4358. // If the Event object wasn't provided to the builder, the object is fetched from the database.
  4359. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4360. func (m *EventMutation) OldTime(ctx context.Context) (v time.Time, err error) {
  4361. if !m.op.Is(OpUpdateOne) {
  4362. return v, fmt.Errorf("OldTime is only allowed on UpdateOne operations")
  4363. }
  4364. if m.id == nil || m.oldValue == nil {
  4365. return v, fmt.Errorf("OldTime requires an ID field in the mutation")
  4366. }
  4367. oldValue, err := m.oldValue(ctx)
  4368. if err != nil {
  4369. return v, fmt.Errorf("querying old value for OldTime: %w", err)
  4370. }
  4371. return oldValue.Time, nil
  4372. }
  4373. // ResetTime resets all changes to the "time" field.
  4374. func (m *EventMutation) ResetTime() {
  4375. m.time = nil
  4376. }
  4377. // SetSerialized sets the "serialized" field.
  4378. func (m *EventMutation) SetSerialized(s string) {
  4379. m.serialized = &s
  4380. }
  4381. // Serialized returns the value of the "serialized" field in the mutation.
  4382. func (m *EventMutation) Serialized() (r string, exists bool) {
  4383. v := m.serialized
  4384. if v == nil {
  4385. return
  4386. }
  4387. return *v, true
  4388. }
  4389. // OldSerialized returns the old "serialized" field's value of the Event entity.
  4390. // If the Event object wasn't provided to the builder, the object is fetched from the database.
  4391. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4392. func (m *EventMutation) OldSerialized(ctx context.Context) (v string, err error) {
  4393. if !m.op.Is(OpUpdateOne) {
  4394. return v, fmt.Errorf("OldSerialized is only allowed on UpdateOne operations")
  4395. }
  4396. if m.id == nil || m.oldValue == nil {
  4397. return v, fmt.Errorf("OldSerialized requires an ID field in the mutation")
  4398. }
  4399. oldValue, err := m.oldValue(ctx)
  4400. if err != nil {
  4401. return v, fmt.Errorf("querying old value for OldSerialized: %w", err)
  4402. }
  4403. return oldValue.Serialized, nil
  4404. }
  4405. // ResetSerialized resets all changes to the "serialized" field.
  4406. func (m *EventMutation) ResetSerialized() {
  4407. m.serialized = nil
  4408. }
  4409. // SetOwnerID sets the "owner" edge to the Alert entity by id.
  4410. func (m *EventMutation) SetOwnerID(id int) {
  4411. m.owner = &id
  4412. }
  4413. // ClearOwner clears the "owner" edge to the Alert entity.
  4414. func (m *EventMutation) ClearOwner() {
  4415. m.clearedowner = true
  4416. }
  4417. // OwnerCleared reports if the "owner" edge to the Alert entity was cleared.
  4418. func (m *EventMutation) OwnerCleared() bool {
  4419. return m.clearedowner
  4420. }
  4421. // OwnerID returns the "owner" edge ID in the mutation.
  4422. func (m *EventMutation) OwnerID() (id int, exists bool) {
  4423. if m.owner != nil {
  4424. return *m.owner, true
  4425. }
  4426. return
  4427. }
  4428. // OwnerIDs returns the "owner" edge IDs in the mutation.
  4429. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  4430. // OwnerID instead. It exists only for internal usage by the builders.
  4431. func (m *EventMutation) OwnerIDs() (ids []int) {
  4432. if id := m.owner; id != nil {
  4433. ids = append(ids, *id)
  4434. }
  4435. return
  4436. }
  4437. // ResetOwner resets all changes to the "owner" edge.
  4438. func (m *EventMutation) ResetOwner() {
  4439. m.owner = nil
  4440. m.clearedowner = false
  4441. }
  4442. // Where appends a list predicates to the EventMutation builder.
  4443. func (m *EventMutation) Where(ps ...predicate.Event) {
  4444. m.predicates = append(m.predicates, ps...)
  4445. }
  4446. // Op returns the operation name.
  4447. func (m *EventMutation) Op() Op {
  4448. return m.op
  4449. }
  4450. // Type returns the node type of this mutation (Event).
  4451. func (m *EventMutation) Type() string {
  4452. return m.typ
  4453. }
  4454. // Fields returns all fields that were changed during this mutation. Note that in
  4455. // order to get all numeric fields that were incremented/decremented, call
  4456. // AddedFields().
  4457. func (m *EventMutation) Fields() []string {
  4458. fields := make([]string, 0, 4)
  4459. if m.created_at != nil {
  4460. fields = append(fields, event.FieldCreatedAt)
  4461. }
  4462. if m.updated_at != nil {
  4463. fields = append(fields, event.FieldUpdatedAt)
  4464. }
  4465. if m.time != nil {
  4466. fields = append(fields, event.FieldTime)
  4467. }
  4468. if m.serialized != nil {
  4469. fields = append(fields, event.FieldSerialized)
  4470. }
  4471. return fields
  4472. }
  4473. // Field returns the value of a field with the given name. The second boolean
  4474. // return value indicates that this field was not set, or was not defined in the
  4475. // schema.
  4476. func (m *EventMutation) Field(name string) (ent.Value, bool) {
  4477. switch name {
  4478. case event.FieldCreatedAt:
  4479. return m.CreatedAt()
  4480. case event.FieldUpdatedAt:
  4481. return m.UpdatedAt()
  4482. case event.FieldTime:
  4483. return m.Time()
  4484. case event.FieldSerialized:
  4485. return m.Serialized()
  4486. }
  4487. return nil, false
  4488. }
  4489. // OldField returns the old value of the field from the database. An error is
  4490. // returned if the mutation operation is not UpdateOne, or the query to the
  4491. // database failed.
  4492. func (m *EventMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  4493. switch name {
  4494. case event.FieldCreatedAt:
  4495. return m.OldCreatedAt(ctx)
  4496. case event.FieldUpdatedAt:
  4497. return m.OldUpdatedAt(ctx)
  4498. case event.FieldTime:
  4499. return m.OldTime(ctx)
  4500. case event.FieldSerialized:
  4501. return m.OldSerialized(ctx)
  4502. }
  4503. return nil, fmt.Errorf("unknown Event field %s", name)
  4504. }
  4505. // SetField sets the value of a field with the given name. It returns an error if
  4506. // the field is not defined in the schema, or if the type mismatched the field
  4507. // type.
  4508. func (m *EventMutation) SetField(name string, value ent.Value) error {
  4509. switch name {
  4510. case event.FieldCreatedAt:
  4511. v, ok := value.(time.Time)
  4512. if !ok {
  4513. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4514. }
  4515. m.SetCreatedAt(v)
  4516. return nil
  4517. case event.FieldUpdatedAt:
  4518. v, ok := value.(time.Time)
  4519. if !ok {
  4520. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4521. }
  4522. m.SetUpdatedAt(v)
  4523. return nil
  4524. case event.FieldTime:
  4525. v, ok := value.(time.Time)
  4526. if !ok {
  4527. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4528. }
  4529. m.SetTime(v)
  4530. return nil
  4531. case event.FieldSerialized:
  4532. v, ok := value.(string)
  4533. if !ok {
  4534. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4535. }
  4536. m.SetSerialized(v)
  4537. return nil
  4538. }
  4539. return fmt.Errorf("unknown Event field %s", name)
  4540. }
  4541. // AddedFields returns all numeric fields that were incremented/decremented during
  4542. // this mutation.
  4543. func (m *EventMutation) AddedFields() []string {
  4544. return nil
  4545. }
  4546. // AddedField returns the numeric value that was incremented/decremented on a field
  4547. // with the given name. The second boolean return value indicates that this field
  4548. // was not set, or was not defined in the schema.
  4549. func (m *EventMutation) AddedField(name string) (ent.Value, bool) {
  4550. return nil, false
  4551. }
  4552. // AddField adds the value to the field with the given name. It returns an error if
  4553. // the field is not defined in the schema, or if the type mismatched the field
  4554. // type.
  4555. func (m *EventMutation) AddField(name string, value ent.Value) error {
  4556. switch name {
  4557. }
  4558. return fmt.Errorf("unknown Event numeric field %s", name)
  4559. }
  4560. // ClearedFields returns all nullable fields that were cleared during this
  4561. // mutation.
  4562. func (m *EventMutation) ClearedFields() []string {
  4563. var fields []string
  4564. if m.FieldCleared(event.FieldCreatedAt) {
  4565. fields = append(fields, event.FieldCreatedAt)
  4566. }
  4567. if m.FieldCleared(event.FieldUpdatedAt) {
  4568. fields = append(fields, event.FieldUpdatedAt)
  4569. }
  4570. return fields
  4571. }
  4572. // FieldCleared returns a boolean indicating if a field with the given name was
  4573. // cleared in this mutation.
  4574. func (m *EventMutation) FieldCleared(name string) bool {
  4575. _, ok := m.clearedFields[name]
  4576. return ok
  4577. }
  4578. // ClearField clears the value of the field with the given name. It returns an
  4579. // error if the field is not defined in the schema.
  4580. func (m *EventMutation) ClearField(name string) error {
  4581. switch name {
  4582. case event.FieldCreatedAt:
  4583. m.ClearCreatedAt()
  4584. return nil
  4585. case event.FieldUpdatedAt:
  4586. m.ClearUpdatedAt()
  4587. return nil
  4588. }
  4589. return fmt.Errorf("unknown Event nullable field %s", name)
  4590. }
  4591. // ResetField resets all changes in the mutation for the field with the given name.
  4592. // It returns an error if the field is not defined in the schema.
  4593. func (m *EventMutation) ResetField(name string) error {
  4594. switch name {
  4595. case event.FieldCreatedAt:
  4596. m.ResetCreatedAt()
  4597. return nil
  4598. case event.FieldUpdatedAt:
  4599. m.ResetUpdatedAt()
  4600. return nil
  4601. case event.FieldTime:
  4602. m.ResetTime()
  4603. return nil
  4604. case event.FieldSerialized:
  4605. m.ResetSerialized()
  4606. return nil
  4607. }
  4608. return fmt.Errorf("unknown Event field %s", name)
  4609. }
  4610. // AddedEdges returns all edge names that were set/added in this mutation.
  4611. func (m *EventMutation) AddedEdges() []string {
  4612. edges := make([]string, 0, 1)
  4613. if m.owner != nil {
  4614. edges = append(edges, event.EdgeOwner)
  4615. }
  4616. return edges
  4617. }
  4618. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  4619. // name in this mutation.
  4620. func (m *EventMutation) AddedIDs(name string) []ent.Value {
  4621. switch name {
  4622. case event.EdgeOwner:
  4623. if id := m.owner; id != nil {
  4624. return []ent.Value{*id}
  4625. }
  4626. }
  4627. return nil
  4628. }
  4629. // RemovedEdges returns all edge names that were removed in this mutation.
  4630. func (m *EventMutation) RemovedEdges() []string {
  4631. edges := make([]string, 0, 1)
  4632. return edges
  4633. }
  4634. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  4635. // the given name in this mutation.
  4636. func (m *EventMutation) RemovedIDs(name string) []ent.Value {
  4637. switch name {
  4638. }
  4639. return nil
  4640. }
  4641. // ClearedEdges returns all edge names that were cleared in this mutation.
  4642. func (m *EventMutation) ClearedEdges() []string {
  4643. edges := make([]string, 0, 1)
  4644. if m.clearedowner {
  4645. edges = append(edges, event.EdgeOwner)
  4646. }
  4647. return edges
  4648. }
  4649. // EdgeCleared returns a boolean which indicates if the edge with the given name
  4650. // was cleared in this mutation.
  4651. func (m *EventMutation) EdgeCleared(name string) bool {
  4652. switch name {
  4653. case event.EdgeOwner:
  4654. return m.clearedowner
  4655. }
  4656. return false
  4657. }
  4658. // ClearEdge clears the value of the edge with the given name. It returns an error
  4659. // if that edge is not defined in the schema.
  4660. func (m *EventMutation) ClearEdge(name string) error {
  4661. switch name {
  4662. case event.EdgeOwner:
  4663. m.ClearOwner()
  4664. return nil
  4665. }
  4666. return fmt.Errorf("unknown Event unique edge %s", name)
  4667. }
  4668. // ResetEdge resets all changes to the edge with the given name in this mutation.
  4669. // It returns an error if the edge is not defined in the schema.
  4670. func (m *EventMutation) ResetEdge(name string) error {
  4671. switch name {
  4672. case event.EdgeOwner:
  4673. m.ResetOwner()
  4674. return nil
  4675. }
  4676. return fmt.Errorf("unknown Event edge %s", name)
  4677. }
  4678. // MachineMutation represents an operation that mutates the Machine nodes in the graph.
  4679. type MachineMutation struct {
  4680. config
  4681. op Op
  4682. typ string
  4683. id *int
  4684. created_at *time.Time
  4685. updated_at *time.Time
  4686. last_push *time.Time
  4687. machineId *string
  4688. password *string
  4689. ipAddress *string
  4690. scenarios *string
  4691. version *string
  4692. isValidated *bool
  4693. status *string
  4694. clearedFields map[string]struct{}
  4695. alerts map[int]struct{}
  4696. removedalerts map[int]struct{}
  4697. clearedalerts bool
  4698. done bool
  4699. oldValue func(context.Context) (*Machine, error)
  4700. predicates []predicate.Machine
  4701. }
  4702. var _ ent.Mutation = (*MachineMutation)(nil)
  4703. // machineOption allows management of the mutation configuration using functional options.
  4704. type machineOption func(*MachineMutation)
  4705. // newMachineMutation creates new mutation for the Machine entity.
  4706. func newMachineMutation(c config, op Op, opts ...machineOption) *MachineMutation {
  4707. m := &MachineMutation{
  4708. config: c,
  4709. op: op,
  4710. typ: TypeMachine,
  4711. clearedFields: make(map[string]struct{}),
  4712. }
  4713. for _, opt := range opts {
  4714. opt(m)
  4715. }
  4716. return m
  4717. }
  4718. // withMachineID sets the ID field of the mutation.
  4719. func withMachineID(id int) machineOption {
  4720. return func(m *MachineMutation) {
  4721. var (
  4722. err error
  4723. once sync.Once
  4724. value *Machine
  4725. )
  4726. m.oldValue = func(ctx context.Context) (*Machine, error) {
  4727. once.Do(func() {
  4728. if m.done {
  4729. err = fmt.Errorf("querying old values post mutation is not allowed")
  4730. } else {
  4731. value, err = m.Client().Machine.Get(ctx, id)
  4732. }
  4733. })
  4734. return value, err
  4735. }
  4736. m.id = &id
  4737. }
  4738. }
  4739. // withMachine sets the old Machine of the mutation.
  4740. func withMachine(node *Machine) machineOption {
  4741. return func(m *MachineMutation) {
  4742. m.oldValue = func(context.Context) (*Machine, error) {
  4743. return node, nil
  4744. }
  4745. m.id = &node.ID
  4746. }
  4747. }
  4748. // Client returns a new `ent.Client` from the mutation. If the mutation was
  4749. // executed in a transaction (ent.Tx), a transactional client is returned.
  4750. func (m MachineMutation) Client() *Client {
  4751. client := &Client{config: m.config}
  4752. client.init()
  4753. return client
  4754. }
  4755. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  4756. // it returns an error otherwise.
  4757. func (m MachineMutation) Tx() (*Tx, error) {
  4758. if _, ok := m.driver.(*txDriver); !ok {
  4759. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  4760. }
  4761. tx := &Tx{config: m.config}
  4762. tx.init()
  4763. return tx, nil
  4764. }
  4765. // ID returns the ID value in the mutation. Note that the ID is only available
  4766. // if it was provided to the builder or after it was returned from the database.
  4767. func (m *MachineMutation) ID() (id int, exists bool) {
  4768. if m.id == nil {
  4769. return
  4770. }
  4771. return *m.id, true
  4772. }
  4773. // SetCreatedAt sets the "created_at" field.
  4774. func (m *MachineMutation) SetCreatedAt(t time.Time) {
  4775. m.created_at = &t
  4776. }
  4777. // CreatedAt returns the value of the "created_at" field in the mutation.
  4778. func (m *MachineMutation) CreatedAt() (r time.Time, exists bool) {
  4779. v := m.created_at
  4780. if v == nil {
  4781. return
  4782. }
  4783. return *v, true
  4784. }
  4785. // OldCreatedAt returns the old "created_at" field's value of the Machine entity.
  4786. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4787. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4788. func (m *MachineMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  4789. if !m.op.Is(OpUpdateOne) {
  4790. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  4791. }
  4792. if m.id == nil || m.oldValue == nil {
  4793. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  4794. }
  4795. oldValue, err := m.oldValue(ctx)
  4796. if err != nil {
  4797. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  4798. }
  4799. return oldValue.CreatedAt, nil
  4800. }
  4801. // ClearCreatedAt clears the value of the "created_at" field.
  4802. func (m *MachineMutation) ClearCreatedAt() {
  4803. m.created_at = nil
  4804. m.clearedFields[machine.FieldCreatedAt] = struct{}{}
  4805. }
  4806. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  4807. func (m *MachineMutation) CreatedAtCleared() bool {
  4808. _, ok := m.clearedFields[machine.FieldCreatedAt]
  4809. return ok
  4810. }
  4811. // ResetCreatedAt resets all changes to the "created_at" field.
  4812. func (m *MachineMutation) ResetCreatedAt() {
  4813. m.created_at = nil
  4814. delete(m.clearedFields, machine.FieldCreatedAt)
  4815. }
  4816. // SetUpdatedAt sets the "updated_at" field.
  4817. func (m *MachineMutation) SetUpdatedAt(t time.Time) {
  4818. m.updated_at = &t
  4819. }
  4820. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  4821. func (m *MachineMutation) UpdatedAt() (r time.Time, exists bool) {
  4822. v := m.updated_at
  4823. if v == nil {
  4824. return
  4825. }
  4826. return *v, true
  4827. }
  4828. // OldUpdatedAt returns the old "updated_at" field's value of the Machine entity.
  4829. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4830. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4831. func (m *MachineMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  4832. if !m.op.Is(OpUpdateOne) {
  4833. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  4834. }
  4835. if m.id == nil || m.oldValue == nil {
  4836. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  4837. }
  4838. oldValue, err := m.oldValue(ctx)
  4839. if err != nil {
  4840. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  4841. }
  4842. return oldValue.UpdatedAt, nil
  4843. }
  4844. // ClearUpdatedAt clears the value of the "updated_at" field.
  4845. func (m *MachineMutation) ClearUpdatedAt() {
  4846. m.updated_at = nil
  4847. m.clearedFields[machine.FieldUpdatedAt] = struct{}{}
  4848. }
  4849. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  4850. func (m *MachineMutation) UpdatedAtCleared() bool {
  4851. _, ok := m.clearedFields[machine.FieldUpdatedAt]
  4852. return ok
  4853. }
  4854. // ResetUpdatedAt resets all changes to the "updated_at" field.
  4855. func (m *MachineMutation) ResetUpdatedAt() {
  4856. m.updated_at = nil
  4857. delete(m.clearedFields, machine.FieldUpdatedAt)
  4858. }
  4859. // SetLastPush sets the "last_push" field.
  4860. func (m *MachineMutation) SetLastPush(t time.Time) {
  4861. m.last_push = &t
  4862. }
  4863. // LastPush returns the value of the "last_push" field in the mutation.
  4864. func (m *MachineMutation) LastPush() (r time.Time, exists bool) {
  4865. v := m.last_push
  4866. if v == nil {
  4867. return
  4868. }
  4869. return *v, true
  4870. }
  4871. // OldLastPush returns the old "last_push" field's value of the Machine entity.
  4872. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4873. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4874. func (m *MachineMutation) OldLastPush(ctx context.Context) (v *time.Time, err error) {
  4875. if !m.op.Is(OpUpdateOne) {
  4876. return v, fmt.Errorf("OldLastPush is only allowed on UpdateOne operations")
  4877. }
  4878. if m.id == nil || m.oldValue == nil {
  4879. return v, fmt.Errorf("OldLastPush requires an ID field in the mutation")
  4880. }
  4881. oldValue, err := m.oldValue(ctx)
  4882. if err != nil {
  4883. return v, fmt.Errorf("querying old value for OldLastPush: %w", err)
  4884. }
  4885. return oldValue.LastPush, nil
  4886. }
  4887. // ClearLastPush clears the value of the "last_push" field.
  4888. func (m *MachineMutation) ClearLastPush() {
  4889. m.last_push = nil
  4890. m.clearedFields[machine.FieldLastPush] = struct{}{}
  4891. }
  4892. // LastPushCleared returns if the "last_push" field was cleared in this mutation.
  4893. func (m *MachineMutation) LastPushCleared() bool {
  4894. _, ok := m.clearedFields[machine.FieldLastPush]
  4895. return ok
  4896. }
  4897. // ResetLastPush resets all changes to the "last_push" field.
  4898. func (m *MachineMutation) ResetLastPush() {
  4899. m.last_push = nil
  4900. delete(m.clearedFields, machine.FieldLastPush)
  4901. }
  4902. // SetMachineId sets the "machineId" field.
  4903. func (m *MachineMutation) SetMachineId(s string) {
  4904. m.machineId = &s
  4905. }
  4906. // MachineId returns the value of the "machineId" field in the mutation.
  4907. func (m *MachineMutation) MachineId() (r string, exists bool) {
  4908. v := m.machineId
  4909. if v == nil {
  4910. return
  4911. }
  4912. return *v, true
  4913. }
  4914. // OldMachineId returns the old "machineId" field's value of the Machine entity.
  4915. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4916. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4917. func (m *MachineMutation) OldMachineId(ctx context.Context) (v string, err error) {
  4918. if !m.op.Is(OpUpdateOne) {
  4919. return v, fmt.Errorf("OldMachineId is only allowed on UpdateOne operations")
  4920. }
  4921. if m.id == nil || m.oldValue == nil {
  4922. return v, fmt.Errorf("OldMachineId requires an ID field in the mutation")
  4923. }
  4924. oldValue, err := m.oldValue(ctx)
  4925. if err != nil {
  4926. return v, fmt.Errorf("querying old value for OldMachineId: %w", err)
  4927. }
  4928. return oldValue.MachineId, nil
  4929. }
  4930. // ResetMachineId resets all changes to the "machineId" field.
  4931. func (m *MachineMutation) ResetMachineId() {
  4932. m.machineId = nil
  4933. }
  4934. // SetPassword sets the "password" field.
  4935. func (m *MachineMutation) SetPassword(s string) {
  4936. m.password = &s
  4937. }
  4938. // Password returns the value of the "password" field in the mutation.
  4939. func (m *MachineMutation) Password() (r string, exists bool) {
  4940. v := m.password
  4941. if v == nil {
  4942. return
  4943. }
  4944. return *v, true
  4945. }
  4946. // OldPassword returns the old "password" field's value of the Machine entity.
  4947. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4948. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4949. func (m *MachineMutation) OldPassword(ctx context.Context) (v string, err error) {
  4950. if !m.op.Is(OpUpdateOne) {
  4951. return v, fmt.Errorf("OldPassword is only allowed on UpdateOne operations")
  4952. }
  4953. if m.id == nil || m.oldValue == nil {
  4954. return v, fmt.Errorf("OldPassword requires an ID field in the mutation")
  4955. }
  4956. oldValue, err := m.oldValue(ctx)
  4957. if err != nil {
  4958. return v, fmt.Errorf("querying old value for OldPassword: %w", err)
  4959. }
  4960. return oldValue.Password, nil
  4961. }
  4962. // ResetPassword resets all changes to the "password" field.
  4963. func (m *MachineMutation) ResetPassword() {
  4964. m.password = nil
  4965. }
  4966. // SetIpAddress sets the "ipAddress" field.
  4967. func (m *MachineMutation) SetIpAddress(s string) {
  4968. m.ipAddress = &s
  4969. }
  4970. // IpAddress returns the value of the "ipAddress" field in the mutation.
  4971. func (m *MachineMutation) IpAddress() (r string, exists bool) {
  4972. v := m.ipAddress
  4973. if v == nil {
  4974. return
  4975. }
  4976. return *v, true
  4977. }
  4978. // OldIpAddress returns the old "ipAddress" field's value of the Machine entity.
  4979. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  4980. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4981. func (m *MachineMutation) OldIpAddress(ctx context.Context) (v string, err error) {
  4982. if !m.op.Is(OpUpdateOne) {
  4983. return v, fmt.Errorf("OldIpAddress is only allowed on UpdateOne operations")
  4984. }
  4985. if m.id == nil || m.oldValue == nil {
  4986. return v, fmt.Errorf("OldIpAddress requires an ID field in the mutation")
  4987. }
  4988. oldValue, err := m.oldValue(ctx)
  4989. if err != nil {
  4990. return v, fmt.Errorf("querying old value for OldIpAddress: %w", err)
  4991. }
  4992. return oldValue.IpAddress, nil
  4993. }
  4994. // ResetIpAddress resets all changes to the "ipAddress" field.
  4995. func (m *MachineMutation) ResetIpAddress() {
  4996. m.ipAddress = nil
  4997. }
  4998. // SetScenarios sets the "scenarios" field.
  4999. func (m *MachineMutation) SetScenarios(s string) {
  5000. m.scenarios = &s
  5001. }
  5002. // Scenarios returns the value of the "scenarios" field in the mutation.
  5003. func (m *MachineMutation) Scenarios() (r string, exists bool) {
  5004. v := m.scenarios
  5005. if v == nil {
  5006. return
  5007. }
  5008. return *v, true
  5009. }
  5010. // OldScenarios returns the old "scenarios" field's value of the Machine entity.
  5011. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  5012. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5013. func (m *MachineMutation) OldScenarios(ctx context.Context) (v string, err error) {
  5014. if !m.op.Is(OpUpdateOne) {
  5015. return v, fmt.Errorf("OldScenarios is only allowed on UpdateOne operations")
  5016. }
  5017. if m.id == nil || m.oldValue == nil {
  5018. return v, fmt.Errorf("OldScenarios requires an ID field in the mutation")
  5019. }
  5020. oldValue, err := m.oldValue(ctx)
  5021. if err != nil {
  5022. return v, fmt.Errorf("querying old value for OldScenarios: %w", err)
  5023. }
  5024. return oldValue.Scenarios, nil
  5025. }
  5026. // ClearScenarios clears the value of the "scenarios" field.
  5027. func (m *MachineMutation) ClearScenarios() {
  5028. m.scenarios = nil
  5029. m.clearedFields[machine.FieldScenarios] = struct{}{}
  5030. }
  5031. // ScenariosCleared returns if the "scenarios" field was cleared in this mutation.
  5032. func (m *MachineMutation) ScenariosCleared() bool {
  5033. _, ok := m.clearedFields[machine.FieldScenarios]
  5034. return ok
  5035. }
  5036. // ResetScenarios resets all changes to the "scenarios" field.
  5037. func (m *MachineMutation) ResetScenarios() {
  5038. m.scenarios = nil
  5039. delete(m.clearedFields, machine.FieldScenarios)
  5040. }
  5041. // SetVersion sets the "version" field.
  5042. func (m *MachineMutation) SetVersion(s string) {
  5043. m.version = &s
  5044. }
  5045. // Version returns the value of the "version" field in the mutation.
  5046. func (m *MachineMutation) Version() (r string, exists bool) {
  5047. v := m.version
  5048. if v == nil {
  5049. return
  5050. }
  5051. return *v, true
  5052. }
  5053. // OldVersion returns the old "version" field's value of the Machine entity.
  5054. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  5055. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5056. func (m *MachineMutation) OldVersion(ctx context.Context) (v string, err error) {
  5057. if !m.op.Is(OpUpdateOne) {
  5058. return v, fmt.Errorf("OldVersion is only allowed on UpdateOne operations")
  5059. }
  5060. if m.id == nil || m.oldValue == nil {
  5061. return v, fmt.Errorf("OldVersion requires an ID field in the mutation")
  5062. }
  5063. oldValue, err := m.oldValue(ctx)
  5064. if err != nil {
  5065. return v, fmt.Errorf("querying old value for OldVersion: %w", err)
  5066. }
  5067. return oldValue.Version, nil
  5068. }
  5069. // ClearVersion clears the value of the "version" field.
  5070. func (m *MachineMutation) ClearVersion() {
  5071. m.version = nil
  5072. m.clearedFields[machine.FieldVersion] = struct{}{}
  5073. }
  5074. // VersionCleared returns if the "version" field was cleared in this mutation.
  5075. func (m *MachineMutation) VersionCleared() bool {
  5076. _, ok := m.clearedFields[machine.FieldVersion]
  5077. return ok
  5078. }
  5079. // ResetVersion resets all changes to the "version" field.
  5080. func (m *MachineMutation) ResetVersion() {
  5081. m.version = nil
  5082. delete(m.clearedFields, machine.FieldVersion)
  5083. }
  5084. // SetIsValidated sets the "isValidated" field.
  5085. func (m *MachineMutation) SetIsValidated(b bool) {
  5086. m.isValidated = &b
  5087. }
  5088. // IsValidated returns the value of the "isValidated" field in the mutation.
  5089. func (m *MachineMutation) IsValidated() (r bool, exists bool) {
  5090. v := m.isValidated
  5091. if v == nil {
  5092. return
  5093. }
  5094. return *v, true
  5095. }
  5096. // OldIsValidated returns the old "isValidated" field's value of the Machine entity.
  5097. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  5098. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5099. func (m *MachineMutation) OldIsValidated(ctx context.Context) (v bool, err error) {
  5100. if !m.op.Is(OpUpdateOne) {
  5101. return v, fmt.Errorf("OldIsValidated is only allowed on UpdateOne operations")
  5102. }
  5103. if m.id == nil || m.oldValue == nil {
  5104. return v, fmt.Errorf("OldIsValidated requires an ID field in the mutation")
  5105. }
  5106. oldValue, err := m.oldValue(ctx)
  5107. if err != nil {
  5108. return v, fmt.Errorf("querying old value for OldIsValidated: %w", err)
  5109. }
  5110. return oldValue.IsValidated, nil
  5111. }
  5112. // ResetIsValidated resets all changes to the "isValidated" field.
  5113. func (m *MachineMutation) ResetIsValidated() {
  5114. m.isValidated = nil
  5115. }
  5116. // SetStatus sets the "status" field.
  5117. func (m *MachineMutation) SetStatus(s string) {
  5118. m.status = &s
  5119. }
  5120. // Status returns the value of the "status" field in the mutation.
  5121. func (m *MachineMutation) Status() (r string, exists bool) {
  5122. v := m.status
  5123. if v == nil {
  5124. return
  5125. }
  5126. return *v, true
  5127. }
  5128. // OldStatus returns the old "status" field's value of the Machine entity.
  5129. // If the Machine object wasn't provided to the builder, the object is fetched from the database.
  5130. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5131. func (m *MachineMutation) OldStatus(ctx context.Context) (v string, err error) {
  5132. if !m.op.Is(OpUpdateOne) {
  5133. return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations")
  5134. }
  5135. if m.id == nil || m.oldValue == nil {
  5136. return v, fmt.Errorf("OldStatus requires an ID field in the mutation")
  5137. }
  5138. oldValue, err := m.oldValue(ctx)
  5139. if err != nil {
  5140. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  5141. }
  5142. return oldValue.Status, nil
  5143. }
  5144. // ClearStatus clears the value of the "status" field.
  5145. func (m *MachineMutation) ClearStatus() {
  5146. m.status = nil
  5147. m.clearedFields[machine.FieldStatus] = struct{}{}
  5148. }
  5149. // StatusCleared returns if the "status" field was cleared in this mutation.
  5150. func (m *MachineMutation) StatusCleared() bool {
  5151. _, ok := m.clearedFields[machine.FieldStatus]
  5152. return ok
  5153. }
  5154. // ResetStatus resets all changes to the "status" field.
  5155. func (m *MachineMutation) ResetStatus() {
  5156. m.status = nil
  5157. delete(m.clearedFields, machine.FieldStatus)
  5158. }
  5159. // AddAlertIDs adds the "alerts" edge to the Alert entity by ids.
  5160. func (m *MachineMutation) AddAlertIDs(ids ...int) {
  5161. if m.alerts == nil {
  5162. m.alerts = make(map[int]struct{})
  5163. }
  5164. for i := range ids {
  5165. m.alerts[ids[i]] = struct{}{}
  5166. }
  5167. }
  5168. // ClearAlerts clears the "alerts" edge to the Alert entity.
  5169. func (m *MachineMutation) ClearAlerts() {
  5170. m.clearedalerts = true
  5171. }
  5172. // AlertsCleared reports if the "alerts" edge to the Alert entity was cleared.
  5173. func (m *MachineMutation) AlertsCleared() bool {
  5174. return m.clearedalerts
  5175. }
  5176. // RemoveAlertIDs removes the "alerts" edge to the Alert entity by IDs.
  5177. func (m *MachineMutation) RemoveAlertIDs(ids ...int) {
  5178. if m.removedalerts == nil {
  5179. m.removedalerts = make(map[int]struct{})
  5180. }
  5181. for i := range ids {
  5182. delete(m.alerts, ids[i])
  5183. m.removedalerts[ids[i]] = struct{}{}
  5184. }
  5185. }
  5186. // RemovedAlerts returns the removed IDs of the "alerts" edge to the Alert entity.
  5187. func (m *MachineMutation) RemovedAlertsIDs() (ids []int) {
  5188. for id := range m.removedalerts {
  5189. ids = append(ids, id)
  5190. }
  5191. return
  5192. }
  5193. // AlertsIDs returns the "alerts" edge IDs in the mutation.
  5194. func (m *MachineMutation) AlertsIDs() (ids []int) {
  5195. for id := range m.alerts {
  5196. ids = append(ids, id)
  5197. }
  5198. return
  5199. }
  5200. // ResetAlerts resets all changes to the "alerts" edge.
  5201. func (m *MachineMutation) ResetAlerts() {
  5202. m.alerts = nil
  5203. m.clearedalerts = false
  5204. m.removedalerts = nil
  5205. }
  5206. // Where appends a list predicates to the MachineMutation builder.
  5207. func (m *MachineMutation) Where(ps ...predicate.Machine) {
  5208. m.predicates = append(m.predicates, ps...)
  5209. }
  5210. // Op returns the operation name.
  5211. func (m *MachineMutation) Op() Op {
  5212. return m.op
  5213. }
  5214. // Type returns the node type of this mutation (Machine).
  5215. func (m *MachineMutation) Type() string {
  5216. return m.typ
  5217. }
  5218. // Fields returns all fields that were changed during this mutation. Note that in
  5219. // order to get all numeric fields that were incremented/decremented, call
  5220. // AddedFields().
  5221. func (m *MachineMutation) Fields() []string {
  5222. fields := make([]string, 0, 10)
  5223. if m.created_at != nil {
  5224. fields = append(fields, machine.FieldCreatedAt)
  5225. }
  5226. if m.updated_at != nil {
  5227. fields = append(fields, machine.FieldUpdatedAt)
  5228. }
  5229. if m.last_push != nil {
  5230. fields = append(fields, machine.FieldLastPush)
  5231. }
  5232. if m.machineId != nil {
  5233. fields = append(fields, machine.FieldMachineId)
  5234. }
  5235. if m.password != nil {
  5236. fields = append(fields, machine.FieldPassword)
  5237. }
  5238. if m.ipAddress != nil {
  5239. fields = append(fields, machine.FieldIpAddress)
  5240. }
  5241. if m.scenarios != nil {
  5242. fields = append(fields, machine.FieldScenarios)
  5243. }
  5244. if m.version != nil {
  5245. fields = append(fields, machine.FieldVersion)
  5246. }
  5247. if m.isValidated != nil {
  5248. fields = append(fields, machine.FieldIsValidated)
  5249. }
  5250. if m.status != nil {
  5251. fields = append(fields, machine.FieldStatus)
  5252. }
  5253. return fields
  5254. }
  5255. // Field returns the value of a field with the given name. The second boolean
  5256. // return value indicates that this field was not set, or was not defined in the
  5257. // schema.
  5258. func (m *MachineMutation) Field(name string) (ent.Value, bool) {
  5259. switch name {
  5260. case machine.FieldCreatedAt:
  5261. return m.CreatedAt()
  5262. case machine.FieldUpdatedAt:
  5263. return m.UpdatedAt()
  5264. case machine.FieldLastPush:
  5265. return m.LastPush()
  5266. case machine.FieldMachineId:
  5267. return m.MachineId()
  5268. case machine.FieldPassword:
  5269. return m.Password()
  5270. case machine.FieldIpAddress:
  5271. return m.IpAddress()
  5272. case machine.FieldScenarios:
  5273. return m.Scenarios()
  5274. case machine.FieldVersion:
  5275. return m.Version()
  5276. case machine.FieldIsValidated:
  5277. return m.IsValidated()
  5278. case machine.FieldStatus:
  5279. return m.Status()
  5280. }
  5281. return nil, false
  5282. }
  5283. // OldField returns the old value of the field from the database. An error is
  5284. // returned if the mutation operation is not UpdateOne, or the query to the
  5285. // database failed.
  5286. func (m *MachineMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5287. switch name {
  5288. case machine.FieldCreatedAt:
  5289. return m.OldCreatedAt(ctx)
  5290. case machine.FieldUpdatedAt:
  5291. return m.OldUpdatedAt(ctx)
  5292. case machine.FieldLastPush:
  5293. return m.OldLastPush(ctx)
  5294. case machine.FieldMachineId:
  5295. return m.OldMachineId(ctx)
  5296. case machine.FieldPassword:
  5297. return m.OldPassword(ctx)
  5298. case machine.FieldIpAddress:
  5299. return m.OldIpAddress(ctx)
  5300. case machine.FieldScenarios:
  5301. return m.OldScenarios(ctx)
  5302. case machine.FieldVersion:
  5303. return m.OldVersion(ctx)
  5304. case machine.FieldIsValidated:
  5305. return m.OldIsValidated(ctx)
  5306. case machine.FieldStatus:
  5307. return m.OldStatus(ctx)
  5308. }
  5309. return nil, fmt.Errorf("unknown Machine field %s", name)
  5310. }
  5311. // SetField sets the value of a field with the given name. It returns an error if
  5312. // the field is not defined in the schema, or if the type mismatched the field
  5313. // type.
  5314. func (m *MachineMutation) SetField(name string, value ent.Value) error {
  5315. switch name {
  5316. case machine.FieldCreatedAt:
  5317. v, ok := value.(time.Time)
  5318. if !ok {
  5319. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5320. }
  5321. m.SetCreatedAt(v)
  5322. return nil
  5323. case machine.FieldUpdatedAt:
  5324. v, ok := value.(time.Time)
  5325. if !ok {
  5326. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5327. }
  5328. m.SetUpdatedAt(v)
  5329. return nil
  5330. case machine.FieldLastPush:
  5331. v, ok := value.(time.Time)
  5332. if !ok {
  5333. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5334. }
  5335. m.SetLastPush(v)
  5336. return nil
  5337. case machine.FieldMachineId:
  5338. v, ok := value.(string)
  5339. if !ok {
  5340. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5341. }
  5342. m.SetMachineId(v)
  5343. return nil
  5344. case machine.FieldPassword:
  5345. v, ok := value.(string)
  5346. if !ok {
  5347. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5348. }
  5349. m.SetPassword(v)
  5350. return nil
  5351. case machine.FieldIpAddress:
  5352. v, ok := value.(string)
  5353. if !ok {
  5354. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5355. }
  5356. m.SetIpAddress(v)
  5357. return nil
  5358. case machine.FieldScenarios:
  5359. v, ok := value.(string)
  5360. if !ok {
  5361. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5362. }
  5363. m.SetScenarios(v)
  5364. return nil
  5365. case machine.FieldVersion:
  5366. v, ok := value.(string)
  5367. if !ok {
  5368. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5369. }
  5370. m.SetVersion(v)
  5371. return nil
  5372. case machine.FieldIsValidated:
  5373. v, ok := value.(bool)
  5374. if !ok {
  5375. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5376. }
  5377. m.SetIsValidated(v)
  5378. return nil
  5379. case machine.FieldStatus:
  5380. v, ok := value.(string)
  5381. if !ok {
  5382. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5383. }
  5384. m.SetStatus(v)
  5385. return nil
  5386. }
  5387. return fmt.Errorf("unknown Machine field %s", name)
  5388. }
  5389. // AddedFields returns all numeric fields that were incremented/decremented during
  5390. // this mutation.
  5391. func (m *MachineMutation) AddedFields() []string {
  5392. return nil
  5393. }
  5394. // AddedField returns the numeric value that was incremented/decremented on a field
  5395. // with the given name. The second boolean return value indicates that this field
  5396. // was not set, or was not defined in the schema.
  5397. func (m *MachineMutation) AddedField(name string) (ent.Value, bool) {
  5398. return nil, false
  5399. }
  5400. // AddField adds the value to the field with the given name. It returns an error if
  5401. // the field is not defined in the schema, or if the type mismatched the field
  5402. // type.
  5403. func (m *MachineMutation) AddField(name string, value ent.Value) error {
  5404. switch name {
  5405. }
  5406. return fmt.Errorf("unknown Machine numeric field %s", name)
  5407. }
  5408. // ClearedFields returns all nullable fields that were cleared during this
  5409. // mutation.
  5410. func (m *MachineMutation) ClearedFields() []string {
  5411. var fields []string
  5412. if m.FieldCleared(machine.FieldCreatedAt) {
  5413. fields = append(fields, machine.FieldCreatedAt)
  5414. }
  5415. if m.FieldCleared(machine.FieldUpdatedAt) {
  5416. fields = append(fields, machine.FieldUpdatedAt)
  5417. }
  5418. if m.FieldCleared(machine.FieldLastPush) {
  5419. fields = append(fields, machine.FieldLastPush)
  5420. }
  5421. if m.FieldCleared(machine.FieldScenarios) {
  5422. fields = append(fields, machine.FieldScenarios)
  5423. }
  5424. if m.FieldCleared(machine.FieldVersion) {
  5425. fields = append(fields, machine.FieldVersion)
  5426. }
  5427. if m.FieldCleared(machine.FieldStatus) {
  5428. fields = append(fields, machine.FieldStatus)
  5429. }
  5430. return fields
  5431. }
  5432. // FieldCleared returns a boolean indicating if a field with the given name was
  5433. // cleared in this mutation.
  5434. func (m *MachineMutation) FieldCleared(name string) bool {
  5435. _, ok := m.clearedFields[name]
  5436. return ok
  5437. }
  5438. // ClearField clears the value of the field with the given name. It returns an
  5439. // error if the field is not defined in the schema.
  5440. func (m *MachineMutation) ClearField(name string) error {
  5441. switch name {
  5442. case machine.FieldCreatedAt:
  5443. m.ClearCreatedAt()
  5444. return nil
  5445. case machine.FieldUpdatedAt:
  5446. m.ClearUpdatedAt()
  5447. return nil
  5448. case machine.FieldLastPush:
  5449. m.ClearLastPush()
  5450. return nil
  5451. case machine.FieldScenarios:
  5452. m.ClearScenarios()
  5453. return nil
  5454. case machine.FieldVersion:
  5455. m.ClearVersion()
  5456. return nil
  5457. case machine.FieldStatus:
  5458. m.ClearStatus()
  5459. return nil
  5460. }
  5461. return fmt.Errorf("unknown Machine nullable field %s", name)
  5462. }
  5463. // ResetField resets all changes in the mutation for the field with the given name.
  5464. // It returns an error if the field is not defined in the schema.
  5465. func (m *MachineMutation) ResetField(name string) error {
  5466. switch name {
  5467. case machine.FieldCreatedAt:
  5468. m.ResetCreatedAt()
  5469. return nil
  5470. case machine.FieldUpdatedAt:
  5471. m.ResetUpdatedAt()
  5472. return nil
  5473. case machine.FieldLastPush:
  5474. m.ResetLastPush()
  5475. return nil
  5476. case machine.FieldMachineId:
  5477. m.ResetMachineId()
  5478. return nil
  5479. case machine.FieldPassword:
  5480. m.ResetPassword()
  5481. return nil
  5482. case machine.FieldIpAddress:
  5483. m.ResetIpAddress()
  5484. return nil
  5485. case machine.FieldScenarios:
  5486. m.ResetScenarios()
  5487. return nil
  5488. case machine.FieldVersion:
  5489. m.ResetVersion()
  5490. return nil
  5491. case machine.FieldIsValidated:
  5492. m.ResetIsValidated()
  5493. return nil
  5494. case machine.FieldStatus:
  5495. m.ResetStatus()
  5496. return nil
  5497. }
  5498. return fmt.Errorf("unknown Machine field %s", name)
  5499. }
  5500. // AddedEdges returns all edge names that were set/added in this mutation.
  5501. func (m *MachineMutation) AddedEdges() []string {
  5502. edges := make([]string, 0, 1)
  5503. if m.alerts != nil {
  5504. edges = append(edges, machine.EdgeAlerts)
  5505. }
  5506. return edges
  5507. }
  5508. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  5509. // name in this mutation.
  5510. func (m *MachineMutation) AddedIDs(name string) []ent.Value {
  5511. switch name {
  5512. case machine.EdgeAlerts:
  5513. ids := make([]ent.Value, 0, len(m.alerts))
  5514. for id := range m.alerts {
  5515. ids = append(ids, id)
  5516. }
  5517. return ids
  5518. }
  5519. return nil
  5520. }
  5521. // RemovedEdges returns all edge names that were removed in this mutation.
  5522. func (m *MachineMutation) RemovedEdges() []string {
  5523. edges := make([]string, 0, 1)
  5524. if m.removedalerts != nil {
  5525. edges = append(edges, machine.EdgeAlerts)
  5526. }
  5527. return edges
  5528. }
  5529. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  5530. // the given name in this mutation.
  5531. func (m *MachineMutation) RemovedIDs(name string) []ent.Value {
  5532. switch name {
  5533. case machine.EdgeAlerts:
  5534. ids := make([]ent.Value, 0, len(m.removedalerts))
  5535. for id := range m.removedalerts {
  5536. ids = append(ids, id)
  5537. }
  5538. return ids
  5539. }
  5540. return nil
  5541. }
  5542. // ClearedEdges returns all edge names that were cleared in this mutation.
  5543. func (m *MachineMutation) ClearedEdges() []string {
  5544. edges := make([]string, 0, 1)
  5545. if m.clearedalerts {
  5546. edges = append(edges, machine.EdgeAlerts)
  5547. }
  5548. return edges
  5549. }
  5550. // EdgeCleared returns a boolean which indicates if the edge with the given name
  5551. // was cleared in this mutation.
  5552. func (m *MachineMutation) EdgeCleared(name string) bool {
  5553. switch name {
  5554. case machine.EdgeAlerts:
  5555. return m.clearedalerts
  5556. }
  5557. return false
  5558. }
  5559. // ClearEdge clears the value of the edge with the given name. It returns an error
  5560. // if that edge is not defined in the schema.
  5561. func (m *MachineMutation) ClearEdge(name string) error {
  5562. switch name {
  5563. }
  5564. return fmt.Errorf("unknown Machine unique edge %s", name)
  5565. }
  5566. // ResetEdge resets all changes to the edge with the given name in this mutation.
  5567. // It returns an error if the edge is not defined in the schema.
  5568. func (m *MachineMutation) ResetEdge(name string) error {
  5569. switch name {
  5570. case machine.EdgeAlerts:
  5571. m.ResetAlerts()
  5572. return nil
  5573. }
  5574. return fmt.Errorf("unknown Machine edge %s", name)
  5575. }
  5576. // MetaMutation represents an operation that mutates the Meta nodes in the graph.
  5577. type MetaMutation struct {
  5578. config
  5579. op Op
  5580. typ string
  5581. id *int
  5582. created_at *time.Time
  5583. updated_at *time.Time
  5584. key *string
  5585. value *string
  5586. clearedFields map[string]struct{}
  5587. owner *int
  5588. clearedowner bool
  5589. done bool
  5590. oldValue func(context.Context) (*Meta, error)
  5591. predicates []predicate.Meta
  5592. }
  5593. var _ ent.Mutation = (*MetaMutation)(nil)
  5594. // metaOption allows management of the mutation configuration using functional options.
  5595. type metaOption func(*MetaMutation)
  5596. // newMetaMutation creates new mutation for the Meta entity.
  5597. func newMetaMutation(c config, op Op, opts ...metaOption) *MetaMutation {
  5598. m := &MetaMutation{
  5599. config: c,
  5600. op: op,
  5601. typ: TypeMeta,
  5602. clearedFields: make(map[string]struct{}),
  5603. }
  5604. for _, opt := range opts {
  5605. opt(m)
  5606. }
  5607. return m
  5608. }
  5609. // withMetaID sets the ID field of the mutation.
  5610. func withMetaID(id int) metaOption {
  5611. return func(m *MetaMutation) {
  5612. var (
  5613. err error
  5614. once sync.Once
  5615. value *Meta
  5616. )
  5617. m.oldValue = func(ctx context.Context) (*Meta, error) {
  5618. once.Do(func() {
  5619. if m.done {
  5620. err = fmt.Errorf("querying old values post mutation is not allowed")
  5621. } else {
  5622. value, err = m.Client().Meta.Get(ctx, id)
  5623. }
  5624. })
  5625. return value, err
  5626. }
  5627. m.id = &id
  5628. }
  5629. }
  5630. // withMeta sets the old Meta of the mutation.
  5631. func withMeta(node *Meta) metaOption {
  5632. return func(m *MetaMutation) {
  5633. m.oldValue = func(context.Context) (*Meta, error) {
  5634. return node, nil
  5635. }
  5636. m.id = &node.ID
  5637. }
  5638. }
  5639. // Client returns a new `ent.Client` from the mutation. If the mutation was
  5640. // executed in a transaction (ent.Tx), a transactional client is returned.
  5641. func (m MetaMutation) Client() *Client {
  5642. client := &Client{config: m.config}
  5643. client.init()
  5644. return client
  5645. }
  5646. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  5647. // it returns an error otherwise.
  5648. func (m MetaMutation) Tx() (*Tx, error) {
  5649. if _, ok := m.driver.(*txDriver); !ok {
  5650. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  5651. }
  5652. tx := &Tx{config: m.config}
  5653. tx.init()
  5654. return tx, nil
  5655. }
  5656. // ID returns the ID value in the mutation. Note that the ID is only available
  5657. // if it was provided to the builder or after it was returned from the database.
  5658. func (m *MetaMutation) ID() (id int, exists bool) {
  5659. if m.id == nil {
  5660. return
  5661. }
  5662. return *m.id, true
  5663. }
  5664. // SetCreatedAt sets the "created_at" field.
  5665. func (m *MetaMutation) SetCreatedAt(t time.Time) {
  5666. m.created_at = &t
  5667. }
  5668. // CreatedAt returns the value of the "created_at" field in the mutation.
  5669. func (m *MetaMutation) CreatedAt() (r time.Time, exists bool) {
  5670. v := m.created_at
  5671. if v == nil {
  5672. return
  5673. }
  5674. return *v, true
  5675. }
  5676. // OldCreatedAt returns the old "created_at" field's value of the Meta entity.
  5677. // If the Meta object wasn't provided to the builder, the object is fetched from the database.
  5678. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5679. func (m *MetaMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
  5680. if !m.op.Is(OpUpdateOne) {
  5681. return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
  5682. }
  5683. if m.id == nil || m.oldValue == nil {
  5684. return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation")
  5685. }
  5686. oldValue, err := m.oldValue(ctx)
  5687. if err != nil {
  5688. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  5689. }
  5690. return oldValue.CreatedAt, nil
  5691. }
  5692. // ClearCreatedAt clears the value of the "created_at" field.
  5693. func (m *MetaMutation) ClearCreatedAt() {
  5694. m.created_at = nil
  5695. m.clearedFields[meta.FieldCreatedAt] = struct{}{}
  5696. }
  5697. // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
  5698. func (m *MetaMutation) CreatedAtCleared() bool {
  5699. _, ok := m.clearedFields[meta.FieldCreatedAt]
  5700. return ok
  5701. }
  5702. // ResetCreatedAt resets all changes to the "created_at" field.
  5703. func (m *MetaMutation) ResetCreatedAt() {
  5704. m.created_at = nil
  5705. delete(m.clearedFields, meta.FieldCreatedAt)
  5706. }
  5707. // SetUpdatedAt sets the "updated_at" field.
  5708. func (m *MetaMutation) SetUpdatedAt(t time.Time) {
  5709. m.updated_at = &t
  5710. }
  5711. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  5712. func (m *MetaMutation) UpdatedAt() (r time.Time, exists bool) {
  5713. v := m.updated_at
  5714. if v == nil {
  5715. return
  5716. }
  5717. return *v, true
  5718. }
  5719. // OldUpdatedAt returns the old "updated_at" field's value of the Meta entity.
  5720. // If the Meta object wasn't provided to the builder, the object is fetched from the database.
  5721. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5722. func (m *MetaMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) {
  5723. if !m.op.Is(OpUpdateOne) {
  5724. return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
  5725. }
  5726. if m.id == nil || m.oldValue == nil {
  5727. return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation")
  5728. }
  5729. oldValue, err := m.oldValue(ctx)
  5730. if err != nil {
  5731. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  5732. }
  5733. return oldValue.UpdatedAt, nil
  5734. }
  5735. // ClearUpdatedAt clears the value of the "updated_at" field.
  5736. func (m *MetaMutation) ClearUpdatedAt() {
  5737. m.updated_at = nil
  5738. m.clearedFields[meta.FieldUpdatedAt] = struct{}{}
  5739. }
  5740. // UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation.
  5741. func (m *MetaMutation) UpdatedAtCleared() bool {
  5742. _, ok := m.clearedFields[meta.FieldUpdatedAt]
  5743. return ok
  5744. }
  5745. // ResetUpdatedAt resets all changes to the "updated_at" field.
  5746. func (m *MetaMutation) ResetUpdatedAt() {
  5747. m.updated_at = nil
  5748. delete(m.clearedFields, meta.FieldUpdatedAt)
  5749. }
  5750. // SetKey sets the "key" field.
  5751. func (m *MetaMutation) SetKey(s string) {
  5752. m.key = &s
  5753. }
  5754. // Key returns the value of the "key" field in the mutation.
  5755. func (m *MetaMutation) Key() (r string, exists bool) {
  5756. v := m.key
  5757. if v == nil {
  5758. return
  5759. }
  5760. return *v, true
  5761. }
  5762. // OldKey returns the old "key" field's value of the Meta entity.
  5763. // If the Meta object wasn't provided to the builder, the object is fetched from the database.
  5764. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5765. func (m *MetaMutation) OldKey(ctx context.Context) (v string, err error) {
  5766. if !m.op.Is(OpUpdateOne) {
  5767. return v, fmt.Errorf("OldKey is only allowed on UpdateOne operations")
  5768. }
  5769. if m.id == nil || m.oldValue == nil {
  5770. return v, fmt.Errorf("OldKey requires an ID field in the mutation")
  5771. }
  5772. oldValue, err := m.oldValue(ctx)
  5773. if err != nil {
  5774. return v, fmt.Errorf("querying old value for OldKey: %w", err)
  5775. }
  5776. return oldValue.Key, nil
  5777. }
  5778. // ResetKey resets all changes to the "key" field.
  5779. func (m *MetaMutation) ResetKey() {
  5780. m.key = nil
  5781. }
  5782. // SetValue sets the "value" field.
  5783. func (m *MetaMutation) SetValue(s string) {
  5784. m.value = &s
  5785. }
  5786. // Value returns the value of the "value" field in the mutation.
  5787. func (m *MetaMutation) Value() (r string, exists bool) {
  5788. v := m.value
  5789. if v == nil {
  5790. return
  5791. }
  5792. return *v, true
  5793. }
  5794. // OldValue returns the old "value" field's value of the Meta entity.
  5795. // If the Meta object wasn't provided to the builder, the object is fetched from the database.
  5796. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5797. func (m *MetaMutation) OldValue(ctx context.Context) (v string, err error) {
  5798. if !m.op.Is(OpUpdateOne) {
  5799. return v, fmt.Errorf("OldValue is only allowed on UpdateOne operations")
  5800. }
  5801. if m.id == nil || m.oldValue == nil {
  5802. return v, fmt.Errorf("OldValue requires an ID field in the mutation")
  5803. }
  5804. oldValue, err := m.oldValue(ctx)
  5805. if err != nil {
  5806. return v, fmt.Errorf("querying old value for OldValue: %w", err)
  5807. }
  5808. return oldValue.Value, nil
  5809. }
  5810. // ResetValue resets all changes to the "value" field.
  5811. func (m *MetaMutation) ResetValue() {
  5812. m.value = nil
  5813. }
  5814. // SetOwnerID sets the "owner" edge to the Alert entity by id.
  5815. func (m *MetaMutation) SetOwnerID(id int) {
  5816. m.owner = &id
  5817. }
  5818. // ClearOwner clears the "owner" edge to the Alert entity.
  5819. func (m *MetaMutation) ClearOwner() {
  5820. m.clearedowner = true
  5821. }
  5822. // OwnerCleared reports if the "owner" edge to the Alert entity was cleared.
  5823. func (m *MetaMutation) OwnerCleared() bool {
  5824. return m.clearedowner
  5825. }
  5826. // OwnerID returns the "owner" edge ID in the mutation.
  5827. func (m *MetaMutation) OwnerID() (id int, exists bool) {
  5828. if m.owner != nil {
  5829. return *m.owner, true
  5830. }
  5831. return
  5832. }
  5833. // OwnerIDs returns the "owner" edge IDs in the mutation.
  5834. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  5835. // OwnerID instead. It exists only for internal usage by the builders.
  5836. func (m *MetaMutation) OwnerIDs() (ids []int) {
  5837. if id := m.owner; id != nil {
  5838. ids = append(ids, *id)
  5839. }
  5840. return
  5841. }
  5842. // ResetOwner resets all changes to the "owner" edge.
  5843. func (m *MetaMutation) ResetOwner() {
  5844. m.owner = nil
  5845. m.clearedowner = false
  5846. }
  5847. // Where appends a list predicates to the MetaMutation builder.
  5848. func (m *MetaMutation) Where(ps ...predicate.Meta) {
  5849. m.predicates = append(m.predicates, ps...)
  5850. }
  5851. // Op returns the operation name.
  5852. func (m *MetaMutation) Op() Op {
  5853. return m.op
  5854. }
  5855. // Type returns the node type of this mutation (Meta).
  5856. func (m *MetaMutation) Type() string {
  5857. return m.typ
  5858. }
  5859. // Fields returns all fields that were changed during this mutation. Note that in
  5860. // order to get all numeric fields that were incremented/decremented, call
  5861. // AddedFields().
  5862. func (m *MetaMutation) Fields() []string {
  5863. fields := make([]string, 0, 4)
  5864. if m.created_at != nil {
  5865. fields = append(fields, meta.FieldCreatedAt)
  5866. }
  5867. if m.updated_at != nil {
  5868. fields = append(fields, meta.FieldUpdatedAt)
  5869. }
  5870. if m.key != nil {
  5871. fields = append(fields, meta.FieldKey)
  5872. }
  5873. if m.value != nil {
  5874. fields = append(fields, meta.FieldValue)
  5875. }
  5876. return fields
  5877. }
  5878. // Field returns the value of a field with the given name. The second boolean
  5879. // return value indicates that this field was not set, or was not defined in the
  5880. // schema.
  5881. func (m *MetaMutation) Field(name string) (ent.Value, bool) {
  5882. switch name {
  5883. case meta.FieldCreatedAt:
  5884. return m.CreatedAt()
  5885. case meta.FieldUpdatedAt:
  5886. return m.UpdatedAt()
  5887. case meta.FieldKey:
  5888. return m.Key()
  5889. case meta.FieldValue:
  5890. return m.Value()
  5891. }
  5892. return nil, false
  5893. }
  5894. // OldField returns the old value of the field from the database. An error is
  5895. // returned if the mutation operation is not UpdateOne, or the query to the
  5896. // database failed.
  5897. func (m *MetaMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5898. switch name {
  5899. case meta.FieldCreatedAt:
  5900. return m.OldCreatedAt(ctx)
  5901. case meta.FieldUpdatedAt:
  5902. return m.OldUpdatedAt(ctx)
  5903. case meta.FieldKey:
  5904. return m.OldKey(ctx)
  5905. case meta.FieldValue:
  5906. return m.OldValue(ctx)
  5907. }
  5908. return nil, fmt.Errorf("unknown Meta field %s", name)
  5909. }
  5910. // SetField sets the value of a field with the given name. It returns an error if
  5911. // the field is not defined in the schema, or if the type mismatched the field
  5912. // type.
  5913. func (m *MetaMutation) SetField(name string, value ent.Value) error {
  5914. switch name {
  5915. case meta.FieldCreatedAt:
  5916. v, ok := value.(time.Time)
  5917. if !ok {
  5918. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5919. }
  5920. m.SetCreatedAt(v)
  5921. return nil
  5922. case meta.FieldUpdatedAt:
  5923. v, ok := value.(time.Time)
  5924. if !ok {
  5925. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5926. }
  5927. m.SetUpdatedAt(v)
  5928. return nil
  5929. case meta.FieldKey:
  5930. v, ok := value.(string)
  5931. if !ok {
  5932. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5933. }
  5934. m.SetKey(v)
  5935. return nil
  5936. case meta.FieldValue:
  5937. v, ok := value.(string)
  5938. if !ok {
  5939. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5940. }
  5941. m.SetValue(v)
  5942. return nil
  5943. }
  5944. return fmt.Errorf("unknown Meta field %s", name)
  5945. }
  5946. // AddedFields returns all numeric fields that were incremented/decremented during
  5947. // this mutation.
  5948. func (m *MetaMutation) AddedFields() []string {
  5949. return nil
  5950. }
  5951. // AddedField returns the numeric value that was incremented/decremented on a field
  5952. // with the given name. The second boolean return value indicates that this field
  5953. // was not set, or was not defined in the schema.
  5954. func (m *MetaMutation) AddedField(name string) (ent.Value, bool) {
  5955. return nil, false
  5956. }
  5957. // AddField adds the value to the field with the given name. It returns an error if
  5958. // the field is not defined in the schema, or if the type mismatched the field
  5959. // type.
  5960. func (m *MetaMutation) AddField(name string, value ent.Value) error {
  5961. switch name {
  5962. }
  5963. return fmt.Errorf("unknown Meta numeric field %s", name)
  5964. }
  5965. // ClearedFields returns all nullable fields that were cleared during this
  5966. // mutation.
  5967. func (m *MetaMutation) ClearedFields() []string {
  5968. var fields []string
  5969. if m.FieldCleared(meta.FieldCreatedAt) {
  5970. fields = append(fields, meta.FieldCreatedAt)
  5971. }
  5972. if m.FieldCleared(meta.FieldUpdatedAt) {
  5973. fields = append(fields, meta.FieldUpdatedAt)
  5974. }
  5975. return fields
  5976. }
  5977. // FieldCleared returns a boolean indicating if a field with the given name was
  5978. // cleared in this mutation.
  5979. func (m *MetaMutation) FieldCleared(name string) bool {
  5980. _, ok := m.clearedFields[name]
  5981. return ok
  5982. }
  5983. // ClearField clears the value of the field with the given name. It returns an
  5984. // error if the field is not defined in the schema.
  5985. func (m *MetaMutation) ClearField(name string) error {
  5986. switch name {
  5987. case meta.FieldCreatedAt:
  5988. m.ClearCreatedAt()
  5989. return nil
  5990. case meta.FieldUpdatedAt:
  5991. m.ClearUpdatedAt()
  5992. return nil
  5993. }
  5994. return fmt.Errorf("unknown Meta nullable field %s", name)
  5995. }
  5996. // ResetField resets all changes in the mutation for the field with the given name.
  5997. // It returns an error if the field is not defined in the schema.
  5998. func (m *MetaMutation) ResetField(name string) error {
  5999. switch name {
  6000. case meta.FieldCreatedAt:
  6001. m.ResetCreatedAt()
  6002. return nil
  6003. case meta.FieldUpdatedAt:
  6004. m.ResetUpdatedAt()
  6005. return nil
  6006. case meta.FieldKey:
  6007. m.ResetKey()
  6008. return nil
  6009. case meta.FieldValue:
  6010. m.ResetValue()
  6011. return nil
  6012. }
  6013. return fmt.Errorf("unknown Meta field %s", name)
  6014. }
  6015. // AddedEdges returns all edge names that were set/added in this mutation.
  6016. func (m *MetaMutation) AddedEdges() []string {
  6017. edges := make([]string, 0, 1)
  6018. if m.owner != nil {
  6019. edges = append(edges, meta.EdgeOwner)
  6020. }
  6021. return edges
  6022. }
  6023. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  6024. // name in this mutation.
  6025. func (m *MetaMutation) AddedIDs(name string) []ent.Value {
  6026. switch name {
  6027. case meta.EdgeOwner:
  6028. if id := m.owner; id != nil {
  6029. return []ent.Value{*id}
  6030. }
  6031. }
  6032. return nil
  6033. }
  6034. // RemovedEdges returns all edge names that were removed in this mutation.
  6035. func (m *MetaMutation) RemovedEdges() []string {
  6036. edges := make([]string, 0, 1)
  6037. return edges
  6038. }
  6039. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  6040. // the given name in this mutation.
  6041. func (m *MetaMutation) RemovedIDs(name string) []ent.Value {
  6042. switch name {
  6043. }
  6044. return nil
  6045. }
  6046. // ClearedEdges returns all edge names that were cleared in this mutation.
  6047. func (m *MetaMutation) ClearedEdges() []string {
  6048. edges := make([]string, 0, 1)
  6049. if m.clearedowner {
  6050. edges = append(edges, meta.EdgeOwner)
  6051. }
  6052. return edges
  6053. }
  6054. // EdgeCleared returns a boolean which indicates if the edge with the given name
  6055. // was cleared in this mutation.
  6056. func (m *MetaMutation) EdgeCleared(name string) bool {
  6057. switch name {
  6058. case meta.EdgeOwner:
  6059. return m.clearedowner
  6060. }
  6061. return false
  6062. }
  6063. // ClearEdge clears the value of the edge with the given name. It returns an error
  6064. // if that edge is not defined in the schema.
  6065. func (m *MetaMutation) ClearEdge(name string) error {
  6066. switch name {
  6067. case meta.EdgeOwner:
  6068. m.ClearOwner()
  6069. return nil
  6070. }
  6071. return fmt.Errorf("unknown Meta unique edge %s", name)
  6072. }
  6073. // ResetEdge resets all changes to the edge with the given name in this mutation.
  6074. // It returns an error if the edge is not defined in the schema.
  6075. func (m *MetaMutation) ResetEdge(name string) error {
  6076. switch name {
  6077. case meta.EdgeOwner:
  6078. m.ResetOwner()
  6079. return nil
  6080. }
  6081. return fmt.Errorf("unknown Meta edge %s", name)
  6082. }