hcju/stacksqa huggingface dataset:
Let $W \subset S$ be an open neighbourhood of $s$. By glueing of relative schemes, see Constructions, Section \ref{constructions-section-relative-glueing}, the functor $$ \left\{ \begin{matrix} X \to U' = U \cup W \text{ of finite presentation} \end{matrix} \right\} \longrightarrow \left\{ \vcenter{ \xymatrix{ X' \ar[d] & Y' \ar[d] \ar[l] \ar[r] & Y \ar[d] \\ U & W \cap U \ar[l] \ar[r] & W } } \right\} $$ is an equivalence of categories. We have $\mathcal{O}_{S, s} = \colim \mathcal{O}_W(W)$ where $W$ runs over the affine open neighbourhoods of $s$. Hence $\Spec(\mathcal{O}_{S, s}) = \lim W$ where $W$ runs over the affine open neighbourhoods of $s$. Thus the category of schemes of finite presentation over $\Spec(\mathcal{O}_{S, s})$ is the limit of the category of schemes of finite presentation over $W$ where $W$ runs over the affine open neighbourhoods of $s$, see Lemma \ref{lemma-descend-finite-presentation}. For every affine open $s \in W$ we see that $U \cap W$ is quasi-compact as $U \to S$ is quasi-compact. Hence $V = \lim W \cap U$ is a limit of quasi-compact and quasi-separated schemes (see Lemma \ref{lemma-directed-inverse-system-has-limit}). Thus also the category of schemes of finite presentation over $V$ is the limit of the categories of schemes of finite presentation over $W \cap U$ where $W$ runs over the affine open neighbourhoods of $s$. The lemma follows formally from a combination of these results.
Proof of (1). Recall that $\Spec(\mathcal{O}_{S, s})$ is the limit of the affine open neighbourhoods of $s$ in $S$. Since $g$ has the property in question, then the restriction of $f'$ to one of these affine open neighbourhoods does too, see Lemmas \ref{lemma-descend-separated-finite-presentation}, \ref{lemma-eventually-proper}, \ref{lemma-descend-finite-finite-presentation}, and \ref{lemma-descend-etale}. Since $f'$ has the given property over $U$ as $f$ does, we conclude as one can check the property locally on the base. \medskip\noindent Proof of (2). If we write $\Spec(\mathcal{O}_{S, s}) = \lim W$ where $W$ runs over the affine open neighbourhoods of $s$ in $S$, then we have $Y_i = \lim W \times_S X_i$. Thus we can use exactly the same arguments as in the proof of (1).
For $n = 1$ this is Lemma \ref{lemma-glueing-near-closed-point}. For $n > 1$ the lemma can be proved in exactly the same way or it can be deduced from it. For example, suppose that $f_i : X_i \to S_i$ are objects of $FP_{S_i}$ and $f : X \to U$ is an object of $FP_U$ and we're given isomorphisms $X_i \times_{S_i} U_i = X \times_U U_i$. By Lemma \ref{lemma-glueing-near-closed-point} we can find a morphism $f' : X' \to U' = S \setminus \{s_1, \ldots, s_{n - 1}\}$ which is of finite presentation, which is isomorphic to $X_i$ over $S_i$, which is isomorphic to $X$ over $U$, and these isomorphisms are compatible with the given isomorphism $X_i \times_{S_n} U_n = X \times_U U_n$. Then we can apply induction to $f_i : X_i \to S_i$, $i \leq n - 1$, $f' : X' \to U'$, and the induced isomorphisms $X_i \times_{S_i} U_i = X' \times_{U'} U_i$, $i \leq n - 1$. This shows essential surjectivity. We omit the proof of fully faithfulness.
The property of being separated, proper, integral, finite, etc is stable under base change. See Schemes, Lemma \ref{schemes-lemma-separated-permanence} and Morphisms, Lemmas \ref{morphisms-lemma-base-change-proper} and \ref{morphisms-lemma-base-change-finite}. Hence if $f$ has the property, then so does $g$. The converse follows from Lemma \ref{lemma-glueing-near-point-properties} but we also give a direct proof here. Namely, if $g$ has to property, then $f$ does in a neighbourhood of $s$ by Lemmas \ref{lemma-descend-separated-finite-presentation}, \ref{lemma-eventually-proper}, \ref{lemma-descend-finite-finite-presentation}, and \ref{lemma-descend-etale}. Since $f$ clearly has the given property over $S \setminus \{s\}$ we conclude as one can check the property locally on the base.
By Lemma \ref{lemma-finite-type-closed-in-finite-presentation} we can find a closed immersion $X \to X'$ over $S$ where $X'$ is a scheme of finite presentation over $S$. By Lemma \ref{lemma-descend-finite-presentation} we can find an $i$ and a morphism of finite presentation $X'_i \to S_i$ whose pull back is $X'$. Set $W = X'_i$.
Since $X$ is quasi-compact and quasi-separated formation of the scheme theoretic image of $X \to S_{i'} \times_{S_i} W$ commutes with restriction to open subschemes (Morphisms, Lemma \ref{morphisms-lemma-quasi-compact-scheme-theoretic-image}). Hence we may and do assume $W$ is affine and maps into an affine open $U_i$ of $S_i$. Let $U \subset S$, $U_{i'} \subset S_{i'}$ be the inverse image of $U_i$. Then $U$, $U_{i'}$,  $S_{i'} \times_{S_i} W = U_{i'} \times_{U_i} W$, and $S \times_{S_i} W = U \times_{U_i} W$ are all affine. This implies $X$ is affine because $X \to S \times_{S_i} W$ is a closed immersion. This also shows the ring map $$ \mathcal{O}(U) \otimes_{\mathcal{O}(U_i)} \mathcal{O}(W) \to \mathcal{O}(X) $$ is surjective. Let $I$ be the kernel. Then we see that $X_{i'}$ is the spectrum of the ring $$ \mathcal{O}(X_{i'}) = \mathcal{O}(U_{i'}) \otimes_{\mathcal{O}(U_i)} \mathcal{O}(W)/I_{i'} $$ where $I_{i'}$ is the inverse image of the ideal $I$ (see Morphisms, Example \ref{morphisms-example-scheme-theoretic-image}). Since $\mathcal{O}(U) = \colim \mathcal{O}(U_{i'})$ we see that $I = \colim I_{i'}$ and we conclude that $\colim \mathcal{O}(X_{i'}) = \mathcal{O}(X)$.
Since $V \to S_{i_2}$ is of finite presentation and $X = \lim_{i \geq i_1} X_i$ we can appeal to Proposition \ref{proposition-characterize-locally-finite-presentation} to find an $i_0 \geq \max(i_1, i_2)$ and a morphism $h : X_{i_0} \to V$ over $S_{i_2}$ such that $X \to X_{i_0} \to V$ is equal to $X \to Y \to V$. For $i \geq i_0$ we get a commutative solid diagram $$ \xymatrix{ X \ar[d] \ar[r] & X_i \ar[r] \ar@{..>}[d] \ar@/_2pc/[dd] |!{[d];[ld]}\hole & X_{i_0} \ar[d]^h \\ Y \ar[r] \ar[d] & Y_i \ar[r] \ar[d] & V \ar[d] \\ S \ar[r] & S_i \ar[r] & S_{i_0} } $$ Since $X \to X_i$ has scheme theoretically dense image and since $Y_i$ is the scheme theoretic image of $Y \to S_i \times_{S_{i_2}} V$ we find that the morphism $X_i \to S_i \times_{S_{i_2}} V$ induced by the diagram factors through $Y_i$ (Morphisms, Lemma \ref{morphisms-lemma-factor-factor}). This proves existence. \medskip\noindent Uniqueness. Let $E_i \subset X_i$ be the equalizer of $f_i$ and $g_i$ for $i \geq i_0$. By Schemes, Lemma \ref{schemes-lemma-where-are-they-equal} $E_i$ is a locally closed subscheme of $X_i$. Since $X_i$ is a closed subscheme of $S_i \times_{S_{i_0}} X_{i_0}$ and similarly for $Y_i$ we see that $$ E_i = X_i \times_{(S_i \times_{S_{i_0}} X_{i_0})} (S_i \times_{S_{i_0}} E_{i_0}) $$ Thus to finish the proof it suffices to show that $X_i \to X_{i_0}$ factors through $E_{i_0}$ for some $i \geq i_0$. To do this we will use that $X \to X_{i_0}$ factors through $E_{i_0}$ as both $f_{i_0}$ and $g_{i_0}$ are compatible with $f$. Since $X_i$ is Noetherian, we see that the underlying topological space $|E_{i_0}|$ is a constructible subset of $|X_{i_0}|$ (Topology, Lemma \ref{topology-lemma-constructible-Noetherian-space}). Hence $X_i \to X_{i_0}$ factors through $E_{i_0}$ set theoretically for large enough $i$ by Lemma \ref{lemma-limit-contained-in-constructible}. For such an $i$ the scheme theoretic inverse image $(X_i \to X_{i_0})^{-1}(E_{i_0})$ is a closed subscheme of $X_i$ through which $X$ factors and hence equal to $X_i$ since $X \to X_i$ has scheme theoretically dense image by construction. This concludes the proof.
By Lemma \ref{lemma-descend-finite-presentation} we can choose an $i \geq i_2$ and a morphism $U \to Y_i$ of finite presentation such that $X = Y \times_{Y_i} U$ (this is where we use that $f$ is of finite presentation). After increasing $i$ we may assume that $U \to Y_i$ is flat, see Lemma \ref{lemma-descend-flat-finite-presentation}. As discussed in Remark \ref{remark-finite-type-gives-well-defined-system} we may and do replace the initial diagram used to define the system $(X_i)_{i \geq i_1}$ by the system corresponding to $X \to U \to S_i$. Thus $X_{i'}$ for $i' \geq i$ is defined as the scheme theoretic image of $X \to S_{i'} \times_{S_i} U$. \medskip\noindent Because $U \to Y_i$ is flat (this is where we use that $f$ is flat), because $X = Y \times_{Y_i} U$, and because the scheme theoretic image of $Y \to Y_i$ is $Y_i$, we see that the scheme theoretic image of $X \to U$ is $U$ (Morphisms, Lemma \ref{morphisms-lemma-flat-base-change-scheme-theoretic-image}). Observe that $Y_{i'} \to S_{i'} \times_{S_i} Y_i$ is a closed immersion for $i' \geq i$ by construction of the system of $Y_j$. Then the same argument as above shows that the scheme theoretic image of $X \to S_{i'} \times_{S_i} U$ is equal to the closed subscheme $Y_{i'} \times_{Y_i} U$. Thus we see that $X_{i'} = Y_{i'} \times_{Y_i} U$ for all $i' \geq i$ and hence the lemma holds with $i_3 = i$.
By the discussion in  Remark \ref{remark-finite-type-gives-well-defined-system} the choice of $i_1$ and $W$ fitting into a diagram as in (\ref{equation-good-diagram}) is immaterial for the truth of the lemma. Thus we choose $W$ as follows. First we choose a closed immersion $X \to X'$ with $X' \to S$ proper and of finite presentation, see Lemma \ref{lemma-proper-limit-of-proper-finite-presentation}. Then we choose an $i_3 \geq i_2$ and a proper morphism $W \to Y_{i_3}$ such that $X' = Y \times_{Y_{i_3}} W$. This is possible because $Y = \lim_{i \geq i_2} Y_i$ and Lemmas \ref{lemma-descend-finite-presentation} and \ref{lemma-eventually-proper}. With this choice of $W$ it is immediate from the construction that for $i \geq i_3$ the scheme $X_i$ is a closed subscheme of $Y_i \times_{Y_{i_3}} W \subset S_i \times_{S_{i_3}} W$ and hence proper over $Y_i$.
According to the discussion in Remark \ref{remark-finite-type-gives-well-defined-system} the choice of $W^1$ fitting into a diagram as in (\ref{equation-good-diagram}) is immaterial for the truth of the lemma. Thus we may choose $W^1 = W^2 \times_{W^4} W^3$. Then it is immediate from the construction of $X^1_i$ that  $a_i \circ p_i = b_i \circ q_i$ and that $$ (q_i, p_i) : X^1_i \longrightarrow X^2_i \times_{b_i, X^4_i, a_i} X^3_i $$ is a closed immersion. \medskip\noindent If $a$ and $b$ are flat and of finite presentation, then so are $p$ and $q$ as base changes of $a$ and $b$. Thus we can apply Lemma \ref{lemma-morphism-good-diagram-flat} to each of $a$, $b$, $p$, $q$, and $a \circ p = b \circ q$. It follows that there exists an $i_9 \in I$ such that $$ (q_i, p_i) : X^1_i \to X^2_i \times_{X^4_i} X^3_i $$ is the base change of $(q_{i_9}, p_{i_9})$ by the morphism by the morphism $X^4_i \to X^4_{i_9}$ for all $i \geq i_9$. We conclude that $(q_i, p_i)$ is an isomorphism for all sufficiently large $i$ by Lemma \ref{lemma-descend-isomorphism}.
Since $f$ is surjective and $X$ is quasi-compact we see that $S$ is quasi-compact. Since $X$ is separated and $f$ is surjective and universally closed (Morphisms, Lemma \ref{morphisms-lemma-integral-universally-closed}), we see that $S$ is separated (Morphisms, Lemma \ref{morphisms-lemma-image-universally-closed-separated}). \medskip\noindent By Lemma \ref{lemma-integral-limit-finite-and-finite-presentation} we can write $X = \lim_i X_i$ with $X_i \to S$ finite. By Lemma \ref{lemma-limit-affine} we see that for $i$ sufficiently large the scheme $X_i$ is affine. Moreover, since $X \to S$ factors through each $X_i$ we see that $X_i \to S$ is surjective. Hence we conclude that $S$ is affine by Lemma \ref{lemma-affine}.